CodeYogi
CodeYogi

Reputation: 1412

Issue in normalizing quiz data

Response format:

const fakeDatabase = {
  quizzes: [{
    id: v4(),
    title: 'Get started',
    text: 'hey',
    completed: true,
    hints: [{
      id: 1,
      text: 'Hint 1'
    }, {
      id: 2,
      text: 'Hint 2'
    }]
  }, {
    id: v4(),
    title: 'What are you waiting for?',
    text: 'ho',
    completed: true,
    hints: [{
      id: 3,
      text: 'Hint 3'
    }, {
      id: 4,
      text: 'Hint 4'
    }]
  }, {
    id: v4(),
    title: 'Remember! create more than you consume',
    text: 'let’s go',
    completed: false,
    hints: [{
      id: 5,
      text: 'Hint 5'
    }, {
      id: 6,
      text: 'Hint 6'
    }]
  }],
};

I have the following schema:

import { Schema, arrayOf } from 'normalizr';

export const hint = new Schema('hints');

export const quiz = new Schema('quizzes', {
  hints: [ hint ]
});

export const arrayOfQuiz = arrayOf(quiz);

But after normalizing I get the following response:

normalize(response, schema.arrayOfQuiz)

So, basically my quiz is normalized properly but hints is kept as it is, I don't know if I am missing something.

Upvotes: 0

Views: 44

Answers (1)

Paul Armstrong
Paul Armstrong

Reputation: 7156

It looks like you're using normalizr v2.x. Only in v3.0.0 was plain array syntaxt [ hint ] added. In v2.x, you need to use arrayOf(hint).

Upvotes: 1

Related Questions