DEV Community

Discussion on: How to store relational data inside Redux

Collapse
 
amitneuhaus profile image
Amit Neuhaus

Hey, great post!
Question about changing data in this kind of structure like adding/deleting children of a parent:
If I want to add a new comment , the comments reducer will add the comment object and the new comment ID to the relevant sections on the comments state, but what about the post state?
Something has to update the comments array in the relevant post state with the new comment ID.
if for example I render a table of posts with comments id's column, the new comment wont show.

Should I access the comments state and for each post row map to see which comments have this post id as parent
Or
Should I just add the comment ID to the comments array in the post state on creation so I won't even need to access the comments state when rendering the posts table?

how would you structure it?