The reason getDerivedStateFromProps is static is to discourage any side-effects during the render phase. For example, updating or using props on the instance.

This isn’t safe anymore with the upcoming async rendering.

It is called when a component is created and each time it recieves a new props.

More info on the react blog: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#fetching-external-data-when-props-change

Written by

Software Consultant, Author, Speaker, React Native|React|GraphQL Dev & Indian Classical Musician http://adhithiravichandran.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store