Skip to content

Instantly share code, notes, and snippets.

@cdiggins
Created January 25, 2018 16:20
Show Gist options
  • Save cdiggins/338a6c31b43f5d88a73bd2aafb4204fb to your computer and use it in GitHub Desktop.
Save cdiggins/338a6c31b43f5d88a73bd2aafb4204fb 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