Jul 29, 2017 · 1 min read
Thanks for your positive feedback.
I was embarrassed as well to write that down without being able to give a simple rule of thumb to solve it yourself. Sorry!
Now that I spent a bit more time on the matter to answer properly your comment, I see 3 ways to improve the normalized aspect of your state:
- Apollo https://github.com/apollographql/apollo-client actually does brilliantly the job of normalizing the incoming external data via graphql. That’s already a huge part of the state shape solved.
- If you discover late that you made a mistake, Normalizr may help you to correct it step by step. It turns a nested JSON to a normalized representation https://github.com/paularmstrong/normalizr. It can do the opposite as well (normalized to nested). It is a great lib, we used it as a selector as well for a treeview component which expected some denormalized data as props.
- When you design the state shape, try to write the state in excel/google spreadsheet, with several tabs and only one table per tab. The table needs to have a single header. Then think of your edit actions, they should only modify one row at a time.
Hope that helps!
