S
S
Sergey Alekseev2018-11-21 15:36:02
Asynchronous programming
Sergey Alekseev, 2018-11-21 15:36:02

React + Redux, how to write to state after data arrives?

Good evening, I make a request to the server in componentDidMount ()
And after I get the props, I need to update the state.
How to check it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-11-21
@serj2000

static getDerivedStateFromProps(props, state) {
  if (props.visas[0] !== state.visa) {
    return {
      visa: props.visas[0],
    };
  }

  return null;
}

The this.props.visa array must always exist.

K
Kappy, 2018-11-21
@KappyJS

It is possible through the flag, along with the data, to change the state

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question