3 ms·
This doesn't surprise me, and I dont think it proves that useEffect is bad design. That being said, I think useEffect is a bit too beginner hostile. It kind of
by pgsandstrom 4y ago
This doesn't surprise me, and I dont think it proves that useEffect is bad design.
That being said, I think useEffect is a bit too beginner hostile. It kind of remindes me of ´reduce´. When used correctly it is really neat. But it can also be fragile and hard to understand. And just like ´reduce´ a simpler and less efficient solution should often be used. When I started using hooks I made wrappers such as "onMount", and it helped me a lot. Beginners should be encouraged to do so, even if it takes away some of useEffects cool features. In time, they will understand the more intricate details.
- rozenmd 4y agoAs the author of the book mentioned, I agree. It seems like the eslint plugin (eslint-plugin-react-hooks) attempts to patch over the beginner-hostility by telling you what to do, but it doesn't actually explain why you should follow its advice.
- valenterry 4y agoUntil the language/runtime gets better support to model those kind of things, I think frameworks like react will be stuck with a suboptimal solution of some kind. It will always either be magical and convenient, or it will be clear but boilerplatey. hooks/useEffect are the former. I hope that there will be improvements here (maybe through typescript) that really allow a better and more explicit concept/expression and composition of effects.