In an earlier question I struggled with normalizing data with normalizr for storing into my Redux store.
This is the outcome: 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);
the outcome of a console.log(normalisedUsers) is now:
{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
Now the question is: how do I refactor the Components in React to get that data displayed. Or am I still in error on how I normalized my data, and should I alter something there?
You haven't actually shared any React components, so I'm just going to guess what you're trying to do. You want a
<Assistant />component to display each assistant, right? And same thing for clients and dentists.Here's how I would do it, assuming the normalised data is in the redux store by now (note, requires lodash):