How does the parent-child component of react multi-level nesting pass the value of the child component to the outermost parent component for use?

how does the parent-child component of react multi-level nesting pass the value of the child component to the outermost parent component for use?
clipboard.png

the nesting relationship is topic.js > ModleForm > form.js > editor.js

what should I do if I want to add, delete, modify and query the outermost topic with the value of the innermost level editor?

Mar.28,2021

the parent component writes a method, then passes it all the way to the child component, and then the child component executes this method


it can be handled by the PubSub publish and subscribe event mechanism, which is convenient, or by the way of props transfer function, but it is more troublesome when the level is deep


if you use redux , put all the values in state so that they are available to the task area.
if there is no redux , write a callback function in the parent component to implement it.
for example:

  

without using redux, the parent component can pass the function to the child component through props, and then call the function in the child component, so that the parent component can get the data from the child component through this function.

Menu