I ❤️ React


I ❤️ React. But, it’s not perfect.

There are features you should avoid.

Here’s “React: The Bad Parts”

👇
Class components - I can’t think of a good reason to use class components anymore.

Use functions. The API is simpler

Use react-error-boundary so you don’t need to use classes for boundaries.
useEffect - A confusing name and API, and it’s overused. Especially for HTTP. Prefer react-query, and/or React Router loaders in 6.4.

Avoid using to sync state. Instead, derive state on render (and memo if needed).

Use rarely for syncing third party state.
Context - It’s fine for rarely changing global settings like user, language, and theme.

But otherwise, pass props, or consider various third party state libraries that handle frequent updates more efficiently.
prop-types - TypeScript is superior.

Prop-types only check at runtime, and only output to the console. It’s useless on CI. 👎

TS checks all files at compile time. It has better autocomplete support, and reliable auto imports.

It’s about equal work to declare a type.

Use TS.
style - Avoid. There are more compelling and scalable options for encapsulating styles.

Try:
Tailwind
CSS modules
CSS-in-JS
Sprinkles
create-react-app - It’s fine for learning.

But, there are faster, more modern, and more powerful alternatives.

Try:
Vite
Next
Remix
Astro
Gatby
Docusaurus
Redwood
NX
Hydrogen
To clarify, there are reasonable use cases for all the items above.

That’s why they exist.

But, generally, in 2022 there are better options worth considering.

View original on X