简体   繁体   中英

Pass value from one parent component to another in React

I have one component Avanger and when the component unmounts i want to transfer its state to the other component named Battle I try to pass the values of the Avanger state to Battle every time when Avanger is updating so am trying this

  componentDidUpdate() {
        console.log(this.state.selectedAvangers)
        return <div><Battle val={this.state.selectedAvangers} /></div>
    }

Keep the state in a parent container (higher order component) and pass the state into these components as props. It sounds like the components that share the same state should be built as presentational stateless components.

Other solutions that don't include prop drilling:

Redux Context API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM