0

I have to pass props from child component to parent, I read the documentation it says passing props is just one-way flow. I guess there is a workaround but I can't figure it out.

  • 2
    Does this answer your question? [Pass props to parent component in React.js](https://stackoverflow.com/questions/22639534/pass-props-to-parent-component-in-react-js) – Bhojendra Rauniyar Apr 01 '21 at 09:10

1 Answers1

0

Yes, there is you have to pass a function to the child component as props.

var getData = (data) => {
  console.log(data);
}


<Child data={this.getData} />

then in Parent Component execute this function and pass the data as an argument. The function will execute in the parent component and displayed in the console. You can use that data from there either by setState or as you wish.

user12551649
  • 366
  • 5
  • 20