6 ms·
> More straightforward, easier to understand? I guess it's subjective? Defintiely not obvious to me, but I do come from an OO background. I had the exact same
by EMM_386 5y ago
> More straightforward, easier to understand? I guess it's subjective? Defintiely not obvious to me, but I do come from an OO background.
I had the exact same reaction to this code block. Using componentDidMount() made it clear what it was doing. Reading the functional version I have no idea how useEffect() equates to componentDidMount().
I am also from an OO background and am currently working on a very large Angular 12 project on the front-end with a C# back-end. I am really enjoying working with Angular ... I can quickly see at a glance what is going on and everything is structured and well organized. React often seems to be targeting developers coming from the "other direction", with a JS background first.
I also don't understand "hooks have made React easier to learn for beginners". My mind glazes over sometimes reading these various examples and I've been in the industry for decades.
To each their own I suppose.
- angelzen 5y agoNot sure this has much to do with OO vs Functional Hooks, more like reading the docs? OO lifecycle: constructor, render, componendDidMount, render, (render, componentDidUpdate, render)* FH lifecycle: (renderFn, useEffectFn | (useLayoutEffectFn, renderFn))+ For more in-depth musing over the exact behavior, see, for example: https://reacttraining.com/blog/useEffect-is-not-the-new-componentDidMount https://reacttraining.com/blog/useEffect-is-not-the-new-comp...
- fuzzy2 5y agoJust out of curiosity, about your Angular project, how large is "very large" in terms of component, module count? How long does it take to build? I'm not satisfied with what I see in my current project at work, but that may be because of Windows and Windows Defender.
- kushan2020 5y agoI think the problem is (not in particularly you) that people want apples to apples comparison. There is no equivalent of lifecycle in hooks! Sure you can give some example of how to produce a componentDidMount, but that defeats the point of hooks. The hooks api is designed to focus on dependencies and what to do in case a dependency changes. When there is an empty array as a dependency , that implies that this hook will never rerun as it has no dependency. Similarly, if there is one dependency, the hook will rerun when that dependency changes.