Best Practices in ReactJS

Tram Ho

Import by structure

  • components
  • images
  • stylesheets
  • hooks
  • utility

Comply with naming conventions

  • PascalCase is mainly for components
  • camelCase is mainly set for functions, hooks, variables, arrays

State grouping

  • Instead of

  • Should use

Destructor props

Clarifying variables

Don’t repeat variable names unnecessarily

Create param object when there are 2 or more params

Component consistency

Create variable to set default value

Share the news now

Source : Viblo