componentWillMount()
componentDidMount()
componentWillReceiveProps()
shouldComponentUpdate()
componentWillUpdate()
componentDidUpdate()
componentWillUnmount()
The next several lessons will cover some of the basic use cases for these lifecycle methods.
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
.");'
```