3 ms·
> This is more about the perils of React switching from component classes where lifecycle methods were explicit and obvious to the multipurpose leaky abstractio
by lewispollard 5y ago
> This is more about the perils of React switching from component classes where lifecycle methods were explicit and obvious to the multipurpose leaky abstraction known as useEffect and the hooks API. To anyone that went through the class phase, this issue is probably obvious and well known.
I don't see how that follows, as someone who transitioned from class components to functional. A functional component is simply a function that runs top to bottom. I don't see any lifecycle issues in the example given.
Yes, if you run that top to bottom on the server and render the output to the client, it's going to return null, since there's no window object. It's obvious once you think of it as just a function, and not an OO abstraction. That they fixed it with a hook doesn't mean the only way to fix it is with a hook. It's just a misunderstanding about SSR on the author's part, I feel.
If anything, lifecycle is much more obvious now, given that you know that returning a function from `useEffect` will call it when the component unmounts, which admittedly isn't obvious without reading the docs.