【发布时间】:2021-12-29 13:20:11
【问题描述】:
在较早的问题中,我在使用 normalizr 规范化数据以存储到我的 Redux 存储中时遇到了困难。
这是结果: https://stackoverflow.com/a/70519781/16303828
const assistant = new schema.Entity("assistants");
const dentist = new schema.Entity("dentists");
const client = new schema.Entity("clients");
const userSchema = {
assistants: [assistant],
dentists: [dentist],
clients: [client]
};
const normalizedUsers = normalize(users, userSchema);
console.log(normalisedUsers) 的结果现在是:
{entities: {…}, result: {…}}
entities:
assistants: {201: {…}, 202: {…}}
clients: {1: {…}, 2: {…}}
dentists: {101: {…}, 102: {…}}
[[Prototype]]: Object
result:
assistants: (2) [201, 202]
clients: (2) [1, 2]
dentists: (2) [101, 102]
[[Prototype]]: Object
[[Prototype]]: Object
现在的问题是:如何重构 React 中的组件以显示该数据。还是我在如何规范化我的数据方面仍然存在错误,我应该在那里改变一些东西吗?
【问题讨论】: