Update code_style.md
- Remove invalid single quotes item - Add TypeScript section - Add item regarding React function components and hooks Signed-off-by: Clemens Zeidler <clemens.zeidler@gmail.com>pull/21833/head
parent
7b882c6393
commit
3eae714269
|
@ -35,12 +35,6 @@ General Style
|
|||
- lowerCamelCase for functions and variables.
|
||||
- Single line ternary operators are fine.
|
||||
- UPPER_SNAKE_CASE for constants
|
||||
- Single quotes for strings by default, for consistency with most JavaScript styles:
|
||||
|
||||
```javascript
|
||||
"bad" // Bad
|
||||
'good' // Good
|
||||
```
|
||||
- Use parentheses or `` ` `` instead of `\` for line continuation where ever possible
|
||||
- Open braces on the same line (consistent with Node):
|
||||
|
||||
|
@ -164,6 +158,14 @@ ECMAScript
|
|||
- Apart from that, newer ES features should be used whenever the author deems them to be appropriate.
|
||||
- Flow annotations are welcome and encouraged.
|
||||
|
||||
TypeScript
|
||||
----------
|
||||
- TypeScript is preferred over the use of JavaScript
|
||||
- Its desirable to convert existing JavaScript files to TypeScript. TypeScript conversions should be done in small
|
||||
chunks without functional changes to ease the review process.
|
||||
- Use full type definitions for function parameters and return values.
|
||||
- Avoid `any` types and `any` casts
|
||||
|
||||
React
|
||||
-----
|
||||
- Pull out functions in props to the class, generally as specific event handlers:
|
||||
|
@ -201,6 +203,8 @@ React
|
|||
this.state = { counter: 0 };
|
||||
}
|
||||
```
|
||||
- Prefer class components over function components and hooks (not a strict rule though)
|
||||
|
||||
- Think about whether your component really needs state: are you duplicating
|
||||
information in component state that could be derived from the model?
|
||||
|
||||
|
|
Loading…
Reference in New Issue