4 ms·
You didn’t actually counter any of the authors’ points. This wonderful functional declarative pipe method of building UI applications where things are built us
by jiofih 7y ago
You didn’t actually counter any of the authors’ points.
This wonderful functional declarative pipe method of building UI applications where things are built using a straight-line series of composed functional transformations can really suck in real world applications as he tries to demonstrate. Anyone building with hooks now can relate to hooks bringing disorder to the codebase.
Has your experience been different? How did you avoid the pitfalls mentioned?
- ng12 7y agoWell #2 isn't really a pitfall, for starters. I have a new feature that solved a problem I had but I can't use it in the code I wrote before I had it without refactoring? I don't think that critique really has anything to do with Hooks, just software development. It's also basically a rephrasing of #3.
- jiofih 7y agoUnless you work on anything beyond a small codebase, and suddenly half of your code cannot be composed with the other.
- pacala 7y ago1. It's not more stuff to learn, it's different stuff to learn, arguably less. Learning Components is not a prerequisite for learning Hooks. Or perhaps I missed the memo, as I've built an app using Hooks, and still haven't need to learn what 'componentWillMount' is supposed to do. 2. Don't mix Components and Hooks. 3. Agreed, change is hard. It's also the only way to avoid stagnation. In the long term, change wins. Or else we'd be programming in JS1995. 4. Insufficient example. What is the business case for a memoized hook returning hooks? Perhaps there is a simpler design, can't comment. 5. There is no global control flow. There is only per function component control flow, which proceeds from top to bottom. Possibly preempted by a hook/hookfn execution, if my early learning curve is to be believed. Which shouldn't matter if one is thinking in terms of 'pure functions returning jsx', as preempted functions do not return, thus have no observable effect. Tip: Only change hook state from event handlers, never from render function code.
- viklove 7y ago> In the long term, change wins. Or else we'd be programming in JS1995. Change for the sake of change is not a sound argument. The thing about hooks is they don't enable a single thing we couldn't already do with HOCs. They are also much harder to read, because stateful logic is now just sprinkled around your render method rather than being isolated to places you know to look for it. I won't be using hooks ever, as far as I'm concerned.
- pacala 7y agoOf course. * "A Critique of React Hooks" * "A Critique of the Change Costs Induced by React Hooks". Objections to React Hooks are stronger if they don't invoke change costs as the primary three concerns.
- runawaybottle 7y agoHe/she gave a very valid critique of state being jammed into your render method, vs state being handled in a predictable pattern in Class components. And lastly, let’s not minimize change-cost. In the real world, it’s a cost. We’re all willing to pay it if it’s necessary, or affordable, but not because someone showed up and said ‘change please’.
- Scarbutt 7y agoUnless you learnt react from non-official sources, you can't avoid learning components because they teach them first.
- pacala 7y agoYou'd be surprised. The only deeper dive into Components is https://reactjs.org/docs/state-and-lifecycle.html https://reactjs.org/docs/state-and-lifecycle.html of the "Main Concepts" section, which I skipped in favor of https://reactjs.org/docs/hooks-state.html https://reactjs.org/docs/hooks-state.html of the "Hooks" section. Haven't got to "Advanced" yet, hope to stay clear of that.
- 7y ago