Nitpick, but React is not a framework, it's a library. People miss this point often eg when they compare React to Angular
I think this is an important nitpick though in your defence. I have just started learning React having become pretty competent with Angular (day job plus some hybrid apps) and I have to say that I'm struggling to understand its popularity compared to Angular. Angular feels fully fleshed out, adheres to MVC mostly and has nice separation of html, css and the UI TS code. I come from a native coding background so this f…
Common mistakes writing React components with hooks
11–20 of 98 posts
Re: Common mistakes writing React components with hooks
#12Nitpick, but React is not a framework, it's a library. People miss this point often eg when they compare React to Angular
Wikipedia says it's both https://en.wikipedia.org/wiki/React_(web_framework)
Providing convenient mechanisms for managing high-level/application state moves them squarely into the framework category, imo.
Re: Common mistakes writing React components with hooks
#13Nitpick, but React is not a framework, it's a library. People miss this point often eg when they compare React to Angular
I think this is an important nitpick though in your defence. I have just started learning React having become pretty competent with Angular (day job plus some hybrid apps) and I have to say that I'm struggling to understand its popularity compared to Angular. Angular feels fully fleshed out, adheres to MVC mostly and has nice separation of html, css and the UI TS code. I come from a native coding background so this f…
How data flows into that tree is not its concern. This is why there's a wide variety of state management libraries available. Empirically I agree teams often get state management wrong, because it requires a different skillset than developing reusable UI components.
Frameworks like Angular make a lot of hard choices outside the view layer for you.
Re: Common mistakes writing React components with hooks
#14I would argue that writing a React component with a hook is a mistake. There is usually an easier/clearer way to solve the problems that hooks are intended to solve with the existing React primitives.
Re: Common mistakes writing React components with hooks
#15The other tips are fine; effects should have a single responsibility and links and buttons should be accessible.
Re: Common mistakes writing React components with hooks
#16Nitpick, but React is not a framework, it's a library. People miss this point often eg when they compare React to Angular
It's a framework which advertises itself as a library.
In reality, there is nothing library-like about bypassing the DOM for rendering and making developers use a custom programming language (JSX)... and please don't give me this tired old argument that JSX is not compulsory! Has anyone ever seen a real React application which does not use JSX? Exactly.
If 99.9999% of developers are using React as a framework, then for all general communication purposes, React is a framework.
Re: Common mistakes writing React components with hooks
#17Nitpick, but React is not a framework, it's a library. People miss this point often eg when they compare React to Angular
Re: Common mistakes writing React components with hooks
#18Nitpick, but React is not a framework, it's a library. People miss this point often eg when they compare React to Angular
Re: Common mistakes writing React components with hooks
#19The first one just feels like a premature optimization. Yes calling setCount forces a rerender of that component, but unless there's lots of subcomponents inside that component, I wouldn't bother. Chances are later you'll need that state in the view, and if you have "unexpected side effects" from rerendering then that is the problem. The other tips are fine; effects should have a single responsibility and links and b…
Yeah we're preventing re-renders there but what are we really preventing / saving, nothing significant?
Anytime I run into a situation where I didn't like how / when a component was re-rendering, it absolutely was not because there was a random bit of state like a counter was in state that didn't need to be... usually it was just a more complex situation unfolding.
It's a good illustrative example, but not a 'common mistake' IMO.
Re: Common mistakes writing React components with hooks
#20Nitpick, but React is not a framework, it's a library. People miss this point often eg when they compare React to Angular
I think React is both and when you describe it as either will depend on how you're using it. If you have a website with a couple of React components here and there, then you have React the library. If you have your app setup as a SPA, with react router, redux, react forms, maybe you started the app with createReactApp, etc, then you are using React the framework. I don't see how you can argue it's not a framework whe…
react-router, redux etc. are all different libraries. Point still stands: You have to pick and assemble these different parts yourself. And then still all those libraries don't call into your code, but your code includes and wires them up.