Skip to content

Commit 4550d88

Browse files
committed
updated code style with class property style
1 parent 6cb6cd3 commit 4550d88

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/code_style.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ const isSecondMarkdownNote = note.type == 'markdown' && note.index == 2
5858
const isNoteHasString = note.content.indexOf('string') != -1
5959
if (isSecondMarkdownNote && isNoteHasString)
6060
```
61+
62+
### Use class property instead of class methods
63+
When writing React components, try to use class property instead of class methods. The reason for this is explained perfectly here:
64+
https://codeburst.io/use-class-properties-to-clean-up-your-classes-and-react-components-93185879f688
65+
66+
**Example**:
67+
68+
```js
69+
// BAD
70+
class MyComponent extends React.Component {
71+
myMethod () {
72+
// code goes here...
73+
}
74+
}
75+
76+
// GOOD
77+
class MyComponent extends React.Component {
78+
myMethod = () => {
79+
// code goes here...
80+
}
81+
}
82+
```

0 commit comments

Comments
 (0)