--- id: 5a24c314108439a4d403617c title: Use the Lifecycle Method componentWillMount challengeType: 6 isRequired: false videoUrl: '' localeTitle: Использовать компонент Lifecycle MethodWillMount --- ## Description
У компонентов React есть несколько специальных методов, которые предоставляют возможности для выполнения действий в определенных точках жизненного цикла компонента. Они называются методами жизненного цикла, или крючками жизненного цикла, и позволяют вам быстро отслеживать компоненты в определенные моменты времени. Это может быть до того, как они будут визуализированы, прежде чем они будут обновлены, прежде чем они получат реквизиты, прежде чем они будут отключены, и так далее. Ниже приведен список некоторых основных методов жизненного цикла: componentWillMount() componentDidMount() componentWillReceiveProps() shouldComponentUpdate() componentWillUpdate() componentDidUpdate() componentWillUnmount() Следующие несколько уроков будут посвящены некоторым основным shouldComponentUpdate() использования этих методов жизненного цикла.
## Instructions
Метод componentWillMount() вызывается перед методом render() когда компонент монтируется в DOM. Запишите что-нибудь на консоль в componentWillMount() - вы можете открыть консоль своего браузера для просмотра вывода.
## Tests
```yml tests: - text: 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.");' ```
## Challenge Seed
```jsx class MyComponent extends React.Component { constructor(props) { super(props); } componentWillMount() { // change code below this line // change code above this line } render() { return
} }; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```