Docs: update frontend style guide to highlight new function paradigm (#40347)

* docs: update frontend style guide to highlight new function paradigm

* docs: add section for default exports

* chore: some typo/syntax/grammar fixes

* chore: change new additions from rule to recommendation

* small typo fix
This commit is contained in:
Uchechukwu Obasi
2021-10-19 07:30:43 +01:00
committed by GitHub
parent 25813db334
commit e226480e06

View File

@ -268,6 +268,7 @@ For code that needs to be used by external plugin:
- Use named exports for all code you want to export from a file.
- Use declaration exports (i.e. `export const foo = ...`).
- Avoid using default exports (for example, `export default foo`).
- Export only the code that is meant to be used outside the module.
### Comments
@ -344,6 +345,14 @@ static defaultProps = { ... }
static defaultProps: Partial<Props> = { ... }
```
### How to declare functional components
We recommend using named regular functions when creating a new react functional component.
```typescript
export function Component(props: Props): ReactElement { ... }
```
## State management
- Don't mutate state in reducers or thunks.