Commit f251345b by Hugo Häggmark Committed by Hugo Häggmark

docs: moved examples to frontend.md

parent f3b9ce31
...@@ -31,37 +31,3 @@ ...@@ -31,37 +31,3 @@
- [ ] The pull request uses helpers `actionCreatorFactory` and `reducerFactory` instead of traditional `switch statement` reducers in Redux. - [ ] The pull request uses helpers `actionCreatorFactory` and `reducerFactory` instead of traditional `switch statement` reducers in Redux.
- [ ] The pull request uses `reducerTester` to test reducers. - [ ] The pull request uses `reducerTester` to test reducers.
- [ ] The pull request does not contain code that access reducers state slice directly, instead the code uses state selectors to access state. - [ ] The pull request does not contain code that access reducers state slice directly, instead the code uses state selectors to access state.
## Common bad practices
### 1. Missing Props/State type
- React Component definitions
```jsx
// good
export class YourClass extends PureComponent<{},{}> { ... }
// bad
export class YourClass extends PureComponent { ... }
```
- React Component constructor
```typescript
// good
constructor(props:Props) {...}
// bad
constructor(props) {...}
```
- React Component defaultProps
```typescript
// good
static defaultProps: Partial<Props> = { ... }
// bad
static defaultProps = { ... }
```
...@@ -4,33 +4,33 @@ Generally we follow the Airbnb [React Style Guide](https://github.com/airbnb/ja ...@@ -4,33 +4,33 @@ Generally we follow the Airbnb [React Style Guide](https://github.com/airbnb/ja
## Table of Contents ## Table of Contents
1. [Basic Rules](#basic-rules) 1. [Basic Rules](#basic-rules)
1. [File & Component Organization](#Organization) 1. [File & Component Organization](#Organization)
1. [Naming](#naming) 1. [Naming](#naming)
1. [Declaration](#declaration) 1. [Declaration](#declaration)
1. [Props](#props) 1. [Props](#props)
1. [Refs](#refs) 1. [Refs](#refs)
1. [Methods](#methods) 1. [Methods](#methods)
1. [Ordering](#ordering) 1. [Ordering](#ordering)
## Basic rules ## Basic rules
* Try to keep files small and focused and break large components up into sub components. - Try to keep files small and focused and break large components up into sub components.
## Organization ## Organization
* Components and types that needs to be used by external plugins needs to go into @grafana/ui - Components and types that needs to be used by external plugins needs to go into @grafana/ui
* Components should get their own folder under features/xxx/components - Components should get their own folder under features/xxx/components
* Sub components can live in that component folders, so small component do not need their own folder - Sub components can live in that component folders, so small component do not need their own folder
* Place test next to their component file (same dir) - Place test next to their component file (same dir)
* Component sass should live in the same folder as component code - Component sass should live in the same folder as component code
* State logic & domain models should live in features/xxx/state - State logic & domain models should live in features/xxx/state
* Containers (pages) can live in feature root features/xxx - Containers (pages) can live in feature root features/xxx
* up for debate? - up for debate?
## Props ## Props
* Name callback props & handlers with a "on" prefix. - Name callback props & handlers with a "on" prefix.
```tsx ```tsx
// good // good
...@@ -56,5 +56,32 @@ render() { ...@@ -56,5 +56,32 @@ render() {
} }
``` ```
- React Component definitions
```jsx
// good
export class YourClass extends PureComponent<{},{}> { ... }
// bad
export class YourClass extends PureComponent { ... }
```
- React Component constructor
```typescript
// good
constructor(props:Props) {...}
// bad
constructor(props) {...}
```
- React Component defaultProps
```typescript
// good
static defaultProps: Partial<Props> = { ... }
// bad
static defaultProps = { ... }
```
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment