Skip to content

Instantly share code, notes, and snippets.

@genadyp
Forked from cdiggins/react-best-practices.md
Created September 6, 2020 06:39
Show Gist options
  • Save genadyp/e37bd93ddcb1c0e2fe098aa5a8abce40 to your computer and use it in GitHub Desktop.
Save genadyp/e37bd93ddcb1c0e2fe098aa5a8abce40 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