Answer the question
In order to leave comments, you need to log in
At what point to receive store changes in a React (Redux) component?
Good afternoon!
I export the component through the connect function.
Initially, the component is rendered with an empty store - then as the store is updated - everything is displayed. When the data is updated, the render function is run - that's right.
But for further work, I need to insert part of the data from props (received via connect) into the state of the component (for example, to bind to text fields). Where is the best place to do it? Tried in componentDidUpdate, but it doesn't seem right. In the render itself, I would not want
Answer the question
In order to leave comments, you need to log in
The issue was resolved, through an additional check for the initial state of the state
state = {
name: null
}
componentDidUpdate(){
if(this.state.name === null){
this.setState({
name: this.props.project.name
})
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question