We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
componentWillMount is deprecated. Please update the article. Thanks
thanku so i want this like ...so agin thanku
Thanks for this!
set the initial state in the constructor
I think the constructor is called first then the other cycles. Right?
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;
Nice, Thanks for the sharing article about this.
componentWillMoumt is deprecated
this article is very usefull