mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 00:54:58 -05: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 named exports for all code you want to export from a file.
|
||||||
- Use declaration exports (i.e. `export const foo = ...`).
|
- 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.
|
- Export only the code that is meant to be used outside the module.
|
||||||
|
|
||||||
### Comments
|
### Comments
|
||||||
@@ -344,6 +345,14 @@ static defaultProps = { ... }
|
|||||||
static defaultProps: Partial<Props> = { ... }
|
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
|
## State management
|
||||||
|
|
||||||
- Don't mutate state in reducers or thunks.
|
- Don't mutate state in reducers or thunks.
|
||||||
|
|||||||
Reference in New Issue
Block a user