Re:A guide to useEffect in React
by rajangdavis on Monday March 11, 2019 @02:31AM
(#19357090)
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.
[ Parent
| on HN ]
I'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).
> 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.
When 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
This 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.
Re:A guide to useEffect in React
by jordanwallwork on Monday March 11, 2019 @05:43AM
(#19357726)
FP?