[React log] The problem of passing values between parent and child components in react

React is a one-way data flow. The
parent component passes the value
to the child component. Through props, the state of the parent component is passed to the child component.
The parent component passes the value to the child as shown in the following figure: it 1
is to introduce some values ​​of the parent into the child component tag, directly define the outgoing, and the child component receives in the props

How to pass the data of the child component back to the parent component?
The child component passes the value to the parent component. The
parent-child component communication can not only pass the value, but also pass the method. The parent component will update the data method to the child component to use, and the child component will pass its own data into this method and call it to change The data of the parent component.
As shown in the figure below: First define a function in the parent component and pass it to the child component. The 2
child component receives this function in props and calls this function to pass the data of the child component to the parent. As shown below:
3

Guess you like

Origin blog.csdn.net/u013034585/article/details/105783211