4 ms·
That's not why hooks were invented. Hooks are by definition component local.
by ng12 6y ago
That's not why hooks were invented. Hooks are by definition component local.
- okareaman 6y agoI'm not a React expert, but I wonder how do you interpret this by Dan Abramov? This is where I got my information about hooks before trying them out: React doesn’t offer a way to “attach” reusable behavior to a component (for example, connecting it to a store). If you’ve worked with React for a while, you may be familiar with patterns like render props and higher-order components that try to solve this. But these patterns require you to restructure your components when you use them, which can be cumbersome and make code harder to follow. If you look at a typical React application in React DevTools, you will likely find a “wrapper hell” of components surrounded by layers of providers, consumers, higher-order components, render props, and other abstractions. While we could filter them out in DevTools, this points to a deeper underlying problem: React needs a better primitive for sharing stateful logic. https://reactjs.org/docs/hooks-intro.html https://reactjs.org/docs/hooks-intro.html
- ng12 6y agoRight, it's not that managing state was hard it's that sharing the logic to manage it was hard. Hooks are additive in that way -- it's offering you the ability to re-use your stateful React logic in the same way you can re-use your declarative JSX.
- okareaman 6y agoThanks for the explanation. React is a great solution for many problems.
- deleted 6y ago[deleted]