2 ms·
That's bullshit; useEffect is a lifecycle hook. From the documentation for the useEffect SETUP parameter: > setup: The function with your Effect’s logic. Your
by Rapzid 4y ago
That's bullshit; useEffect is a lifecycle hook.
From the documentation for the useEffect SETUP parameter:
> setup: The function with your Effect’s logic. Your setup function may also optionally return a cleanup function. When your component is first added to the DOM, React will run your setup function. After every re-render with changed dependencies, React will first run the cleanup function (if you provided it) with the old values, and then run your setup function with the new values. After your component is removed from the DOM, React will run your cleanup function one last time.
- dgb23 4y agoIt absolutely is. But the article and the comments above mention that it’s more useful to have the mental model of synchronizing side effects with state. It’s good advice, because it addresses a major stumbling block people struggle with. After that the code and the way useEffect is used becomes simpler.
- Rapzid 4y agoFrom the linked article in this thread: > Here's the crux of the issue: useEffect is not a lifecycle hook. That doesn't leave much room for ambiguity; seems like a definitive statement. Many don't see any nuance here and then go around blasting people for saying useEffect is a lifecycle hook because they read on some blog the exact opposite. But anyway, what is a lifecycle hook if not a way to synchronize two systems... ( ͡° ͜ʖ ͡°)