I read the React Docs regarding the constructor method and what it can use to set the state and binding function, but is it really necessary in most cases?
What is the difference between execution
export default class MyClass extends Component { constructor(props) { super(props); this.state = { foo: 'bar', }; this.member = 'member'; this.someFunction = this.anotherFunction(num); } anotherFunction = (num) => num * 2; render() {
and just putting everything outside the constructor like
export default class MyClass extends Component { state = { foo: 'bar', }; member = 'member'; someFunction = this.anotherFunction(num); anotherFunction = (num) => num * 2; render() {
Is one option preferable to the other and are there any performance issues I should be aware of? This has distorted me a little, and I cannot find a concrete answer there.
source share