A
A
Aidar Khayatov2019-09-03 13:37:14
JavaScript
Aidar Khayatov, 2019-09-03 13:37:14

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

2 answer(s)
D
davidnum95, 2019-09-03
@davidnum95

https://ru.reactjs.org/docs/react-component.html#s...

A
Aidar Khayatov, 2019-09-03
@Haiatov

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 question

Ask a Question

731 491 924 answers to any question