Hacker News new | ask | show | jobs
by postalrat 2017 days ago
IMO the new context and hook are the best thing that react has done. Hats off to whoever designed them.
1 comments

Yep. I've watched the video that @BreakfastB0b referenced and must say I do not see how this can't be done with new hooks/effects.

I can easily have all the user settings accessed inside a small effect and react to events or not depending on the settings and it's composable and reusable.

Testing with jest/enzyme is still the same. I'm writing selectors, simulating clicks and the component rerenders. Mocking the effects or functions that effects use is also simple. With jest 26 and modern fake timers it's easy to test async effects and changes of state too.

I guess the only flaw of hooks/effects is that they not efficient because of so many effects fetching the same state but they are efficient enough. For example, mobx would be extremely efficient in that regard (any store.value access is just that, not a useState call with new () => {} instantiated on every rerender.