componentWillMount()
componentDidMount()
componentWillReceiveProps()
shouldComponentUpdate()
componentWillUpdate()
componentDidUpdate()
componentWillUnmount()
Следующие несколько уроков будут посвящены некоторым основным shouldComponentUpdate()
использования этих методов жизненного цикла. componentWillMount()
вызывается перед методом render()
когда компонент монтируется в DOM. Запишите что-нибудь на консоль в componentWillMount()
- вы можете открыть консоль своего браузера для просмотра вывода. MyComponent
должен отображать элемент div
.
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
следует вызывать в 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
.");'
```