normalizr возвращает массив неопределенных значений - PullRequest
0 голосов
/ 16 мая 2018

Я использую реагировать + редукс и пытаюсь нормализовать возврат API.Мой код выглядит следующим образом:

схема:

import { schema} from "normalizr";

export const walkthroughSchema = new schema.Entity("walkthroughs");
export const walkthroughListSchema = [walkthroughSchema];

моя выборка:

static listAllWalkthroughs() {
   return window
  .fetch("http://127.0.0.1:3000/walkthroughs")
  .then(response => {
    return response.json();
  })
  .then(jsonData => {
    const normalized = normalize(jsonData, schemas.walkthroughListSchema );
    console.log("api - response", jsonData);
    console.log("api - normalized dsata ", normalized);
  });
}

ответ выборки:

[0 : {
  name: "name 1",
  ID: "5aa7317906ddabf5f7d76c58",
  username: "",
  url: "https://google.com", status: "", …},

1 : {
  name: "name 2",
  ID: "5aa7346706ddabf5f7d76d5d",
  username: "",
  url: "https://google.com",
  status: "", …},
2 : {
  name: "name 3",
  ID: "5acd9740d53edd2200818bb1",
  username: "",
  url: "https://google.com",
  status: "", …}]

когда я печатаю нормированные данные, это результат:

entities:
  walkthoroughs: {
    undefined: {
      id : "5acd9740d53edd2200818bb1",name: 
        "name 3",
            status: "",
            steps: [],
            url: "https://google.com",
            username:""

    }
  }
result: {[
    0: undefined,
    1: undefined,
    2: undefined
]
}

Вопрос в том, что я делаю не так?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...