From 4550d888bbaa11873529ac340ddbcb5af9917786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20H=C6=B0ng?= Date: Sat, 27 Oct 2018 09:47:15 +0700 Subject: [PATCH] updated code style with class property style --- docs/code_style.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/code_style.md b/docs/code_style.md index 154ec039..d8f458d7 100644 --- a/docs/code_style.md +++ b/docs/code_style.md @@ -58,3 +58,25 @@ const isSecondMarkdownNote = note.type == 'markdown' && note.index == 2 const isNoteHasString = note.content.indexOf('string') != -1 if (isSecondMarkdownNote && isNoteHasString) ``` + +### Use class property instead of class methods +When writing React components, try to use class property instead of class methods. The reason for this is explained perfectly here: +https://codeburst.io/use-class-properties-to-clean-up-your-classes-and-react-components-93185879f688 + +**Example**: + +```js +// BAD +class MyComponent extends React.Component { + myMethod () { + // code goes here... + } +} + +// GOOD +class MyComponent extends React.Component { + myMethod = () => { + // code goes here... + } +} +``` \ No newline at end of file