Skip to content

Instantly share code, notes, and snippets.

@rayets123
Forked from cdiggins/react-best-practices.md
Created March 30, 2023 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayets123/68327a03554e5914e2f11e3d86cc16af to your computer and use it in GitHub Desktop.
Save rayets123/68327a03554e5914e2f11e3d86cc16af to your computer and use it in GitHub Desktop.
React Best Practices

React Best practices

I have summarized and compiled a list of React.JS best practices from various sources across the internet.

From the React docs

Presentational and Container Components

Separate components into presentational or container components

  • Presentation components

    • concerned with how things look
    • allow containment via this.props.children
    • often have styles
    • have no dependencies on rest of approach
    • don't specify how data is loaded or mutated
    • Receive data and callbacks exclusively via props.
    • Rarely have their own state (when they do, it’s UI state rather than data).
  • Container components

    • concerned with how things work
    • usually don’t have any DOM markup of their own except for maybe some wrapping divs
    • provide data and behavior to presentational or other container components.
    • are often stateful
  • Because functional components are easier to understand, use them unless you need state, lifecycle hooks, or performance optimizations

Best Practices From Other Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment