3 ms·
Not to deny any and all of the points made, but getting beyond those, it would be nice to get an assessment of using the new react hooks and especially the co
by talkingtab 8y ago
Not to deny any and all of the points made, but getting beyond those, it would be nice to get an assessment of using the new react hooks and especially the context in this manner?
I find the whole thing of reusing components in React harder than I would hope, and I find the hook API has let me remove massive amounts of code. The context API does the same thing, so combining them in some way ...?
- kansface 8y agoHooks are an attempt to reuse stateful logic. This is a problem that React never solved well moving from mixins, to higher order components, to children as render functions, and finally to hooks (maybe!). Ideally, hooks would also fully replace eg usage of react-redux even if that isn't their stated goal (managing global state across components is not really the same thing as reusing stateful logic). In fact, I don't really care about the former at all in the case of the later. The current hooks API is not up to the task, or even up to integrating with react-redux given constraints around the new concurrent rendering and reasonable performance [1]. Hooks run during render with no ability to bail, while react-redux requires a way to avoid calling render in the first place to avoid every connected component re-rendering on every state change (ie, basically the whole tree)[2]. The new context API is also not ready for the limelight [3]. Hooks would solve some problems but at the expense of introducing yet another way to do some things. They can't replace react-redux or even provider a cleaner binding. Using hooks is risky because the API really ought to change to make them more useful, and they aren't particularly performant or powerful. 1. https://github.com/facebook/react/issues/14110#issuecomment-447040520 https://github.com/facebook/react/issues/14110#issuecomment-... 2. https://github.com/facebook/react/issues/14110#issuecomment-448070764 https://github.com/facebook/react/issues/14110#issuecomment-... 3. https://github.com/facebook/react/issues/14110#issuecomment-448074060 https://github.com/facebook/react/issues/14110#issuecomment-...
- talkingtab 8y agoWhen the context API was released I began to rip out redux. After things went well with that, I no longer use redux, and I was a big fan of redux. A problems I had with using context was what seemed to me like a crufty way to access it - the whole wrapping things in a Provider. Now, I can just rip out more code and use the context hook. I'm a big fan of technologies that let you rip out tons of code. My experienc e then is that hooks are a great improvement. So far ....