Replacing ‘componentWillReceiveProps’ with ‘getDerivedStateFromProps’by@amanshu_kataria
304,157 reads

Replacing ‘componentWillReceiveProps’ with ‘getDerivedStateFromProps’

May 13th 2018
5 min
by @amanshu_kataria 304,157 reads
tldt arrow
Read on Terminal Reader🖨️

Too Long; Didn't Read

GetDerivedStateFromProps is a static method which is invoked after a component is instantiated as well as when it receives new props. The only way to update state is returning an object. If you don’t want to update any state, simply return null. Release of React 17 will deprecate some lifecycle methods introduced in React 16.3. For example we’re getting some data from firebase and displaying it in the form of stats. Here’s the code for the same.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Replacing ‘componentWillReceiveProps’ with ‘getDerivedStateFromProps’
Amanshu Kataria HackerNoon profile picture

@amanshu_kataria

Amanshu Kataria

Learn More
LEARN MORE ABOUT @AMANSHU_KATARIA'S EXPERTISE AND PLACE ON THE INTERNET.
react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!
Hackernoon hq - po box 2206, edwards, colorado 81632, usa