Questions tagged [getderivedstatefromprops]

`getDerivedStateFromProps` is invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object to update the state, or null to update nothing.

https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops

37 questions
0
votes
1 answer

what's the use of getDerivedStateFromProps (or how do you fire it?)

I have the following 'List' component where I'm trying to update this.state from props. I can't seem to get getDrivedStateFromProps to work correctly with componentDidUpdate. There's a problem with the logic but it doesn't seem that gDSFC ever…
DCR
  • 14,737
  • 12
  • 52
  • 115
0
votes
1 answer

Returning state after API call inside getDerivedStateFromProps

I have a react component that receives props for filtering from its parent. When the parent props change I use getDerivedStateFromProps in the child in the following code: static getDerivedStateFromProps(props, state) { if (props.filter === null)…
user3728304
  • 17
  • 1
  • 4
0
votes
0 answers

Why will function not update in props?

I have a form where I am entered data and submitting the form. Then I want to display the data. I call the function using props. But for some reason the function will not update in props. Action: export function getTagFormSubmit(vin){ return…
Roro
  • 427
  • 2
  • 8
  • 20
0
votes
1 answer

When to really use getDerivedStateFromProps?

I'm having trouble determining if my component hierarchy really needs getDerivedStateFromProps, if the cases where it is needed is really as rare as the documentation makes it sound. It might be a fundamental misunderstanding about React/Redux…
0
votes
2 answers

Cannot setState from props in React from parent to child

I am trying to pass -from parent to child component- some data as props and I would like to set this prop to initial state. class EditContact extends Component { constructor(props) { super(props); this.state = { name:…
Gabi C
  • 461
  • 3
  • 10
  • 21
0
votes
1 answer

Lots of logic in getDerivedStateFromProps, skinny vs fat gDSFP

I'm wondering if it is bad practice to have 'fat' gDSFP functions. Currently, I have a component that takes in some data and does a bunch of data manipulation function getDrivedStateFromProps(nextProps, prevState) { // start doing data…
Jstuff
  • 1,266
  • 2
  • 16
  • 27
0
votes
2 answers

getDerivedStateFromProps not working for my application. How can I replace componentWillRecieveProps?

I'm creating a React application with Redux, and on my Account Settings page I have a form that I want pre-populated with the user's info and then give them the ability to edit the fields and update their profile. My code is as follows: class…
Adam Johnston
  • 1,399
  • 2
  • 12
  • 23
1 2
3