I am woking on a sample ReactJS application, where I want to pass a variable from one component to another.
class Layout extends React.Component{
constructor(props) {
super(props);
this.state = {keyword: ''};
}
render() {
return (
<div className="wrapper">
<Search />
<Listing />
</div>
);
}
};
ReactDOM.render(
<Layout />, app
);
In the above code, I want to pass a variable from <Search /> component to <Listing /> component.
Searchhappens at the time you want to pass the variable toListing?onSubmitprop forSearchand then handle theonSubmitinLayout. @Andrew's answer below.