Re:React is becoming a black box
by brundolf on Thursday September 03, 2020 @02:01PM
(#24366753)
People keep mentioning lifecycle methods, but I very rarely found myself using them. Those, too, were a code smell to me, especially if they caused side-effects in application state. I don't see them as an integral part of the class-component paradigm at all.
[ Parent
| on HN ]
Re:React is becoming a black box
by dragonwriter on Thursday September 03, 2020 @02:07PM
(#24366846)
If you don't need lifecycle methods in class components, you probably don't need hooks much in functional components, since the most used hooks are direct substitutes for lifecycle methods.
I saw hooks more as a replacement for this.state/setState (or your state management library's equivalent). So if you've got a dropdown that can be either open or closed, for example. Is that not the case?
Re:React is becoming a black box
by dragonwriter on Thursday September 03, 2020 @03:53PM
(#24368105)
Well, useState/useDispatch is a substitute for that, useEffect is a substitute for most lifecycle methods, useMemo is a hybrid that is basically useState + useEffect for updates.
IME, useEffect is where the complications tend to arise (assuming you are using a state management library for non-local state, which seems to be the dominant approach even with functional components.)