I want to send data from child component to parent component in React. Looking up the data, there is only class type and there is no functional document. What syntax can you use to pass data over?
Asked
Active
Viewed 2,757 times
-2
-
could you give an example or usecase? – Prateek Thapa Oct 11 '20 at 14:38
1 Answers
2
You can use a callback function to use pass data from child to parent.
function Parent(){
const doSomethingWithDataFromChild(data) {...do something here}
return <Child passDataToParent={doSomethingWithDataFromChild} />
}
function Child(props) {
props.passDataToParent(childData);
return ...
}
Mind that there are some side effects of doing things this way. For the more curated answers you need to provide some more context and/or code examples like what is the use case etc.

Md Sabbir Alam
- 4,937
- 3
- 15
- 30