Component Structure and Organization:
- Use functional components and hooks instead of class components for most use cases;
- Divide components into presentational and container components: container components handle data fetching or state and pass data to presentational components, which focus on UI;
- Structure files by feature or domain in large apps. For example, group all files related to a feature (components, hooks, styles, tests) in one folder. Keep shared generic components (like UI elements) in a separate common folder;
- Ensure each component has a clear purpose. If a component grows too complex or handles unrelated concerns, break it into smaller components.
Hooks:
- Only call hooks at the top level of your components or custom hooks (never inside loops or conditionals);
- Always specify all necessary dependencies in hooks like
useEffect
anduseCallback
to avoid stale state or infinite loops; - Use
useMemo
to memoize expensive calculations so they run only when inputs change, and `useCallb