Re:React Table v7 – Hooks for building fast and extendable d...
by pogorniy on Tuesday March 10, 2020 @04:57PM
(#22539600)
It's one-way control. There is no reasonable way to implement narrative "now my filter resides in global state. Whenever component changes, it's reflected in the state. Whenever state changes it's reflected in component". I asked this question in spectrum community https://spectrum.chat/react-table/general/how-to-control-fil...
[ Parent
| on HN ]
Re:React Table v7 – Hooks for building fast and extendable d...
by tannerlinsley on Tuesday March 10, 2020 @05:04PM
(#22539667)
There's definitely a difference between taking table state and storing it somewhere globally for use later and 100% controlling the table state from outside of the table. Doing the latter involves listening to the table state for changes in an effect, shipping the new state up to your higher-than-component storage location, detecting in that same component a change in the global storage location (usually just a memoized prop or hook of sorts) and updating the table state with your updated global state using either a table method like instance.setFilter or even a state reducer if you want total control. The tools are in place and the API is flexible enough to do what you are referring to. I'm sorry your comment in Spectrum got lost in the noise and that you had to resort to posting your question on here.
Re:React Table v7 – Hooks for building fast and extendable d...
by pogorniy on Tuesday March 10, 2020 @05:18PM
(#22539813)
Thanks for detailed explanation and your time. I do understand that things I want to achieve are achievable. But I'm not happy with the complexity price I have to pay.
I believe that moving in the implementation between local and global state should be a snap. It's a matter of time when need to move local state to global will arise. And hooks have nothing to propose for that.
Good luck with your project.
Re:React Table v7 – Hooks for building fast and extendable d...
by ng12 on Tuesday March 10, 2020 @06:05PM
(#22540298)
There's nothing wrong with having useStore() next to useTable() and using a few effects to keep them in sync.
Re:React Table v7 – Hooks for building fast and extendable d...
by pogorniy on Wednesday March 11, 2020 @05:28AM
(#22544340)
This would be acceptableway to go. But I did not manage to get it working. Saw your comment how to fix, but don't have code to validate that everything would work as expected.
Thanks.