We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Rajab Muhamed Rajab • 3 years ago

componentWillMoumt is deprecated
this article is very usefull

Ulan Rakymzhan • 4 years ago

componentWillMount is deprecated. Please update the article. Thanks

Anonymous • 4 years ago

thanku so i want this like ...so agin thanku

temmietope • 4 years ago

Thanks for this!

Syed Sirajul Islam Anik • 5 years ago
set the initial state in the constructor


I think the constructor is called first then the other cycles. Right?

shashankj • 4 years ago

yes..Actually the author should correct the post because the sequence is
1. constructor
2. ComponentWillMount
3. Render
4. ComponentDidMount
5. Render

Try this code for proof:-
----------------------------

import React, { Component } from 'react';

class App extends Component {
componentWillMount(){
alert('ComponentWillMount');
console.log('First this called');
}
constructor(props){
alert('before super');
super(props);
alert(' before state constructor');
this.state = {
data: 'Jordan Belfort'
}
alert('after state constructor');
}

getData(){
setTimeout(() => {
console.log('Our data is fetched');
this.setState({
data: 'Hello WallStreet'
})
}, 1000)
}

componentDidMount(){
alert('ComponentDidMount');
this.getData();
}

render() {
alert('render');
return(
<div>
{this.state.data}
</div>
)
}
}

export default App;

Risyandi • 5 years ago

Nice, Thanks for the sharing article about this.