November 2019
Beginner
804 pages
20h 1m
English
React components have a specific lifecycle, just like Angular and Vue.js ones.
In the case of class components, hooking into this lifecycle is, once again, simply a matter of implementing specific methods in your components.
Here's an example:
import React from 'react';
import ReactDOM from 'react-dom';
...
export class LifecycleAwareComponent extends React.Component {
constructor(props) {
super(props);
...
}
render() {
...
}
componentDidMount() {
console.log('componentDidMount lifecycle hook called');
}
...
}
In this example, we used the componentDidMount lifecycle hook, which is called as soon as the component's initialization is completed.
There are many other lifecycle hooks in React. Wojciech Maj (a member of the React ...
Read now
Unlock full access