I am trying to better understand Maxime's answer to this question . My representative is not tall enough to comment on the answer, so I will ask a new question here.
The part about setting a normalized state makes sense. Then he continues to talk about how you will create the selector, this part of his answer is given below and his code block is shown.
In your logic or view (e.g. using Angular) you need your nested structure so that you can iterate over your array, and therefore you don't want to iterate over a string array of identifiers. Instead, you want actualContent: ActualContent [] ;.
To do this, you create a selector. Each time your store changes, your selector will start and generate a new “look” of your raw data.
const getBlogContents = (blogContentsState, actualContentsState) =>
blogContentsState
.allIds
.map(blogContentId => ({
...blogContentsState.byId[blogContentId],
actualContent: blogContentsState
.byId[blogContentId]
.actualContentIds
.map(actualContentId => actualContentsState.byId[actualContentId])
}));
My question is, is there still a type definition BlogContent
with an array actualContent
nested?
export interface BlogContent {
id: string;
header: string;
tags: string[];
title: string;
actualContent: ActualContent[]; <------ NESTED
}
I don’t quite understand what the selector does getBlogContents
and how it will be used in the component that wants to display blogContents with the actualContents nested list, can this be explained in more detail?
source
share