How can the status of child components be obtained in real time in the parent component of React?

there is a state in the child component that needs to be used in the parent component, so how can the parent component respond in real time?

the only way you can think of is to use callbacks to get the status of child components directly from the parent component. For example, what is obtained by using this.refs.xxx.state.xxx is not real-time, can it be obtained in real-time? Like redux, can you respond in real time without additional processing?

Aug.25,2021

check getChildContext


 

you don't want to use callbacks, nor do you want to use refs . Then you'll have to use redux .
in the child component, hand over state directly to redux . It would be nice to get the parent component directly from redux .

in addition, your refs is not real-time data. I guess there is something wrong with you. This shouldn't be. The data obtained by
refs is the current state of the component it points to.

Menu