Skip to content

Instantly share code, notes, and snippets.

@uladzislau-stuk
Last active December 24, 2019 17:52
Show Gist options
  • Save uladzislau-stuk/45771e663b10d534f875eb18a2dcedb5 to your computer and use it in GitHub Desktop.
Save uladzislau-stuk/45771e663b10d534f875eb18a2dcedb5 to your computer and use it in GitHub Desktop.
[React project structure, best practice]

Best practices

  • pascalCase for component file name and folder name
  • lowerCamelCase for Higher Order Component file and folder name
  • lowercase for all other root directory folders. For example: src, components, assets

Anti-pattern

  • anti-pattern to copy properties that never change to the state (just access .props directly in that case)

Note: Using props to generate state in getInitialState often leads to duplication of “source of truth”, i.e. where the real data is.

Issues

  1. Deeply nested directories in JavaScript can cause many pain points, such as difficulty writing relative imports and updating those imports.

Structuring project recommends:

Articles: How I structure my React apps

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