Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Article Idea: Lean React #42

Open
raphael-arce opened this issue Dec 25, 2024 · 0 comments
Open

Article Idea: Lean React #42

raphael-arce opened this issue Dec 25, 2024 · 0 comments

Comments

@raphael-arce
Copy link
Owner

raphael-arce commented Dec 25, 2024

Opinionated easier to read React:

  • prefer self-closing components (<Component /> over <Component></Component>)
  • use children over label/title/text
  • prefer native web elements/apis instead of react states (e.g. dialogs)
  • extract your states instead of prop-drilling
  • keep your components small with a humanly readable (and understandable!) name
  • Avoid useEffects to make things happen when a value changes. Prefer normal functions.
  • don't use useEffect directly, extract it in a named hook that describes what it does (self-documentating code > commented documentation)
  • Avoid higher order functions (e.g. a function that takes an argument derived from a state and generates a function that uses this state. Often ends up in using an outdated value)
  • self-documenting code (what is happening?) > code comments (if previous not enough, why is it happening? > documentation (if previous not enough)
  • prefer smaller, „dumber“ components that are used for one purpose (small, dumb > bigger, „smarter“ components that are used for many purposes (-> low coupling high cohesion)
  • prefer map over repetition when possible
  • if the array becomes big, prefer class: "hidden" over completely adding/removing elements from the dom

TBC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant