Assume the following situation:
1. Page has many posts
2. Post has many comments
I have the following reducers:
1. PagesReducer
2. PostsReducer
3. PostReducer
4. CommentsReducer
I have the following state right now:
pagesByTitle: {
dorrisPage: {
isFetching: false,
data: {
_id: "..."
title: "dorrisPage",
},
posts: [
{
isFetching: false,
data: {
_id: "..",
body: ".."
},
comments: [..]
}
]
}
}
The above structure looked okay initially, but I realized that I had to pass down the action
for child states. For example, if I dispatched an action called
ADD_COMMENT
I would pass the action down to PagesReducer
, PostsReducer
, PostReducer
, and CommentsReducer
, and finally the CommentsReducer
will handle that action. I think this is when I realized why normalizing states is recommended in Redux.
Can you help me with the following questions?
- Is my motivation for normalizing states correct in this context?
- What's the best way to normalize the example states?