Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

React Component Lifecycle - getDerivedStateFromProps

The life-cycle method is invoked before calling the render method, both during the initial mounting phase and the update phase. This method returns an object which will be updated in the comgetDerivedStateFromProps ponents state, if no state change is required this method returns null. The main purpose of this method is to update the state based on changes to props.

This is a new life-cycle method introduced in React 16.3, intended to replace the legacy life-cycle method componentWillReceiveProps. This life-cycle method can be used for purposes like displaying Transition animation by comparing previous and next props, handle dynamic scrolling by using previous and next props to decide whether to scroll up or down. This method get called for every render, hence if possible we should avoid using this method with other alternatives.

Below is the syntax for getDerivedStateFromProps


This post first appeared on C# Guide, please read the originial post: here

Share the post

React Component Lifecycle - getDerivedStateFromProps

×

Subscribe to C# Guide

Get updates delivered right to your inbox!

Thank you for your subscription

×