Component life cycle methods

Various methods are executed at specific points in a component's lifecycle. Let's look at them.

componentWillMount()

The componentWillMount() method is invoked once immediately before the initial rendering occurs. If you call setState within this method, render() will see the updated state and will be executed only once despite the state change.

componentDidMount()

The componentDidMount() method is invoked only on the client side. It is invoked only once after initial rendering has occurred.

componentWillReceiveProps(nextProps)

Directly mutating the properties passed to a component will have no effect because there is no way for React to find value changes as it doesn't watch the properties directly. But sometimes, it is ...

Get JavaScript: Moving to ES2015 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.