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

Replacing ‘componentWillReceiveProps’ with ‘getDerivedStateFromProps’

tldt arrow
Read on Terminal Reader
Read this story w/o Javascript

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.

Company Mentioned

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

@amanshu_kataria

Amanshu Kataria

Software Engineer


Receive Stories from @amanshu_kataria

react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!