-2

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?

1
  • could you give an example or usecase? Commented Oct 11, 2020 at 14:38

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.