Reputation: 717
I want to pass props into another component. Specifically, I want to pass props into another component, when the user clicks a submit button. For some reason, that doesn't seem to be working... Are there only some places where you can pass props to children components.
OnSubmit(e){
e.preventDefault(e)
<SearchRresults data="test"/>
}
Upvotes: 0
Views: 1201
Reputation: 106
There are only places where you can return children elements: 1) from render() method in a class based component or 2) as a return in functional components.
To be able to pass props to the children from a parent, when the form is submitted in the parent, you need to save submit values in the component state(or in redux or whatever state you able to use) and pass state as a prop to the children. here is example: https://codesandbox.io/s/03k6ypnm0n
And actually just read official react docs introduction.
Upvotes: 1