3 ms·
When do you actually need to use hooks? I saw a nice visual where hooks ended up reducing code, but I am not sure I grok it.
by rajangdavis 8y ago
When do you actually need to use hooks? I saw a nice visual where hooks ended up reducing code, but I am not sure I grok it.
- snek 8y agoWhen you want to work with state in a component (so most of the time) but are too stubborn to admit FP isn't the right choice for the job
- jameslk 8y agoThis is my feeling too to be honest. I think hooks are very misguided. Unfortunately it's no longer FP anymore when your "referential transparency" has been completely blown away.
- jordanwallwork 8y agoFP?
- jameslk 8y agoFunctional Programming
- jameslk 8y agoI've been using React in projects large and small for years and I can remember VERY FEW situations where I said to myself "gee I wish I could bundle a bunch of state or side effects together and share it between components like React mixins of lore". If you can't think of a situation where you need it, that's probably because you don't. Anything plain old JavaScript class components can't handle here were solved by using HOCs/render prop patterns or React context (often in the form of state management libraries such as Redux).
- deleted 8y ago[deleted]
- sorahn 8y ago> HOCs/render prop Both of these inflate the VDOM, and present themselves as a false hierarchy that your app requires. HOCs artificially inflate the props that any component requires, and it's harder to see what props you're actually supposed to pass to the component, vs the ones that should come from a HOC. Hooks remove a lot of these anti-patterns.