componentWillMount()
componentDidMount()
componentWillReceiveProps()
shouldComponentUpdate()
componentWillUpdate()
componentDidUpdate()
componentWillUnmount()
The next several lessons will cover some of the basic use cases for these lifecycle methods.
##### Note: The ``` componentWillMount ``` Lifecycle method will be deprecated in a future version of 16.X and removed in version 17. [(Source)](https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html)
componentWillMount()
method is called before the render()
method when a component is being mounted to the DOM. Log something to the console within componentWillMount()
- you may want to have your browser console open to see the output.
MyComponent
should render a div
element.
testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.find('div').length === 1; })(), 'MyComponent
should render a div
element.');
- text: console.log
should be called in componentWillMount
.
testString: assert((function() { const lifecycle = React.createElement(MyComponent).type.prototype.componentWillMount.toString().replace(/ /g,''); return lifecycle.includes('console.log('); })(), 'console.log
should be called in componentWillMount
.');
```