4 ms·
> Futher, Redux doesn't solve synchronization issues in situations where you can't represent the data the same way. I would argue that synchronizing data betwe
by pault 8y ago
> Futher, Redux doesn't solve synchronization issues in situations where you can't represent the data the same way.
I would argue that synchronizing data between multiple representations is an anti-pattern, and the exact anti-pattern that redux, with its emphasis on a single source of truth, was designed to solve. Synchronizing state is almost always going to lead to hard to diagnose bugs in edge cases. There's even a blog post on why it's a bad idea on the official react blog [0]
My solution to this problem is to use computed values generated by a library with memoization like reselect. I structure my data as close as possible to the API data models and use selectors to transform the models into the data structures that disparate UI components require. If you need to change your UI component, you don't need to refactor your store, and if you need to change your store structure, you don't need to refactor your UI components.
[0]: https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html#common-bugs-when-using-derived-state https://reactjs.org/blog/2018/06/07/you-probably-dont-need-d...