mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00
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:
@ -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.
|
||||
|
Reference in New Issue
Block a user