Skip to content

Instantly share code, notes, and snippets.

@satishSKY
Forked from cdiggins/react-best-practices.md
Created August 17, 2020 12:35
Show Gist options
  • Save satishSKY/625d96c1de6e8e4217b1ac8f7b0e7eb8 to your computer and use it in GitHub Desktop.
Save satishSKY/625d96c1de6e8e4217b1ac8f7b0e7eb8 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