I started learning React when we could simply use state and create object instead of using constructor(props){ super(props)
Now, I see many libraries where they are still using
class Master extends Component {
constructor(props){
super(props)
So my first question is if there is an advantage of using constructor (props) super(props) and then setting up state? instead of just creating state object?
Second question, I wanted to implement react-native-slowlog in the native app I am making.
Throughout the code I have created the state object directly instead of using constructor.
The documentation for the react-native-slowlog shows this way to use it
class Master extends Component {
constructor(props){
super(props)
slowlog(this, /.*/)
this.state = this.getDataSource(props)
this.shouldComponentUpdate = shouldComponentUpdate.bind(this)
}
...
}
Where they call slowlog(this, /.*/) inside the constructor, so my question is can I avoid using constructor here? or is it okay if I create a constructor where I do slowlog(this, /.*/) and then create state object outside the constructor?
class Master extends Component {
constructor(){
super()
slowlog(this, /.*/)
}
state = {
searchCoin: false
}