3 ms·
> I've found that people that learned class-based React first and then switched to modern function-based React often have more trouble with useEffect than peopl
by orangepanda 4y ago
> I've found that people that learned class-based React first and then switched to modern function-based React often have more trouble with useEffect than people who learned functional components directly
I’d say its the opposite; people who used lifecycle methods know that useEffect and friends eliminates an entire class of bugs. People who started with hooks dont understand the problems it solved, and only see the quirks
- chrisbaker98 4y agoI'm far more experienced with React function components than with class components, so I'm curious, what are some of the problems with class components and how did hooks solve them?
- spion 4y agoThis was not the only design possible. The main problem with lifecycle methods was that you couldn't have multiple of them. There is absolutely nothing about the design of React that necessitated hooks to fix that issue. You could have this API this.addListener('mount', () => { // do things on mount // return cleanup to be called on unmount return () => cleanup() }) called from the constructur of a component. With this you could setup multiple listeners and make sure they're all cleaned up. But no, the syntax wasn't "clean" (you'd pass `this` as an argument to the "custom hooks" equivalent"), so instead we got this error-prone order-dependent design that doesn't allow conditional execution and runs on every render.