-
Notifications
You must be signed in to change notification settings - Fork 6
React Development Guidelines
Sahil Bhatia edited this page May 16, 2020
·
12 revisions
- Use create-react-app starter kit to get started. DON'T eject it
- Configure eslint-react for your project and editor. Keep the configuration in
.eslintrc
file - Configure prettier-eslint
- Use husky for configuring pre-commit hooks
- Install prop-types
- Jest, ReactTestingLibrary - for functional testing
- Cypress - for E2E tests
-
Do NOT ignore
warning
anderrors
in terminal or browser console -
ONLY use functional components (i.e. no classes)
-
Prefer ES6 syntaxes
-
Use fetch, async await - for API calls
-
Always add new module to package.json (using
yarn add <package-name>
) -
Before adding a new package, check if it's already installed
-
Don't use both
yarn.lock
andpackage-json.lock
in the same project -
Add all environment variables to
.env.local
file with REACTAPP prefix -
Add comments (wherever required) to explain logic
-
Never assign a value directly to export
- Use kebab-case (hyphen separated lowercase words) for naming folders
- Match your component-related files with the component name (use PascalCase - first letter of each word capitalized, no spacing between words)
- Don't manipulate the DOM directly
- DOM should NOT be source of data
- Components should be loosely coupled
- Avoid use of ref
-
Think - the React way
- Step 1: Break The UI Into A Component Hierarchy
- Step 2: Build A Static Version in React
- Step 3: Identify The Minimal (but complete) Representation Of UI State
- Step 4: Identify Where Your State Should Live
- Step 5: Add Inverse Data Flow
- Every component should follow “single responsibility principle”
- Every component should be self-sufficient, reusable
- Own DOM
- Own Styles (use styled-components)
- No hard-coding of values
- No hard-coded height/width/margin/padding
- Follow composition pattern (not inheritance)
- Create pure, stateless, functional (presentation/dumb) components
- Every component should have:
- Render “array” of components instead of “loop” (“loop” should not be part of the render method’s “return” block)
- Always create wrappers over third party components
- Import packages in following sequence:
- core/important imports from third party modules
- other third party imports
- leave an empty line
- import custom modules
- leave an empty line
- import CSS modules (from third-party libraries)
- README.md
- package.json
- yarn.lock
- public/
- favicon.ico
- manifest.json
- robots.txt
- index.html
- src/
- assets/
- images/
- fonts/
- svgs
- containers/
- A folder per route. This contains components to be rendered matching given route. Usually
containers
.
- A folder per route. This contains components to be rendered matching given route. Usually
- components/
- core/
- these components should be pure functions and should not have any project specific logic
- shared/
// project specific re-usable components. Example:
- User/
- User.js
- User.style.js
- User.test.js
- User/
- layout/
- core/
- actionConstants/ // simple constatnt declarations for action names
- actions/
// functions that returns
action
object (passed todispatch
) - sagas/ // middleware for Redux - handles side-effects
- apis/ // services for making API calls
- reducers/ // entities that manipulate the store
- selectors/ // re-select files - used for memoization
- hooks/
- Custom hooks (if any)
- helpers/
- Shared functions (which may not be pure functions)
- utils/
- Shared functions (MUST BE pure functions)
- assets/
Copyright © Josh Software Pvt. Ltd.