How to pass state back to parent in React?

后端 未结 7 1414
时光说笑
时光说笑 2020-12-05 04:08

I have a form that has a submit button. That form calls a function onclick that sets the state of something from false to true. I then want to pass this state back to the pa

相关标签:
7条回答
  • 2020-12-05 05:00

    Simple Steps:

    1. Create a component called Parent.
    2. In Parent Component create a method that accepts some data and sets the accepted data as the parent's state.
    3. Create a component called Child.
    4. Pass the method created in Parent to child as props.

    5. Accept the props in parent using this.props followed by method name and pass child's state to it as argument.

    6. The method will replace the parent's state with the child's state.
    0 讨论(0)
提交回复
热议问题