Answer the question
In order to leave comments, you need to log in
What is the best way to make asynchronous requests in a React container component so that updated props come to the presentation component?
Good evening! Faced such a problem.
Answer the question
In order to leave comments, you need to log in
As a result, it turned out to solve the problem using getDerivedStateFromProps. I compare the state
with the incoming props and update the state. Then I pass the state data as props to children
static getDerivedStateFromProps(nextProps, prevState) {
if (prevState.projects !== nextProps.projects) {
}
return {
projects: nextProps.projects,
};
}
Everything works, but the data comes after the render() method is called. Therefore, the component is not rendered and throws an error.
How to fix it?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question