Want to use arrow function in constructor of a react component? Option 1 is generally more preferable for certain reasons.
1 2 3 4 5 6 7 8 9 | class Test extends React.Component{ constructor(props) { super(props); this.doSomeThing = this.doSomeThing.bind(this); } doSomething() {} } |
Prototype method is cleaner to extend. Child class can override or extend doSomething with
1 2 3 4 | doSomething() { super.doSomething(); ... } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.