React derived state from props => http://dertasinal.nnmcloud.ru/d?s=YToyOntzOjc6InJlZmVyZXIiO3M6MjE6Imh0dHA6Ly9iaXRiaW4uaXQyX2RsLyI7czozOiJrZXkiO3M6MzA6IlJlYWN0IGRlcml2ZWQgc3RhdGUgZnJvbSBwcm9wcyI7fQ== Child components receive this prop via getDerivedStateFromProps The duplicate children perform a calculation that includes the prop whenever their own local fields are changed. : { selectedTab : nextProps. This is why moving the fetch to componentDidMount has no perceptible effect in the vast majority of cases. Note that the above example is very simple, is prone to race conditions if the responses arrive out of order and does no cancellation on new values or component unmount. But it can be a premature optimization as well when learning only about React. A common question which comes up then: It would be similar to functional stateless components then. This example is about having two lists - the content of the second list is determined by the selection made in the first list. Subscribe to Techdomain Get the latest posts delivered right to your inbox. For example, the code snippet you showed above might fetch external data unnecessarily. Maybe it will be changed at some point. You can read more about it. In addition, state can be passed as props to child components too. In one of the first versions the code looked like this: class List extends React. What can be done to improve the situation here? DerivedStateFromProps and calling child methods : reactjs - This is how it looks like: To model this situation in React. Then, scan for all possible arguments in calls of this function and modify the possible values set accordingly. In this example class Counter extends React. Component { constructor props { super props ; this. Component { constructor props { super props ; this. If handleChange triggered from textbox and initialCount is updated also child Counter component is updated correctly because getDerivedStateFromProps static method provides this. But changing count value in Counter component with updating local state via handleIncrease and handleDecrease methods it prolematic. Problem is getDerivedStateFromProps re-trigger this time and resets count value. React derived state from props I did not expect this because Counter component local state updating parent Main component is not updating. Summary my getDerivedStateFromProps usage is incorrect or there is another solution for my scenario. In fact even your has a bug in it. If you re-render the parent component more often, you will lose user input. This shows why trying to sync state to props is a bad idea and should be avoided. Both of these approaches are described in. The blog post includes detailed examples with demos so I strongly recommend to check it out. You actually don't need to duplicate state: class Counter extends React. Component { render { return + {this. Component { constructor props { super props ; this.