I want to pass a function to a child component through React Router. I tried the following but it doesn't seem to work.
class App extends Component {
constructor(props) {
super(props)
}
render() {
return (
<div className="App">
<div className="content">
<div className="centered-wrapper">
<Switch>
<Route exact path="/" component={Welcome} />
<Route path="/life" render={props => <Life sayHello = {this.sayHello()} />} />
</Switch>
</div>
</div>
);
}
}
export default App;
I wanted to call sayHello() in the Life component as follows:
<div className="hello">{ this.props.sayHello() } I'm <Link to="/life">Marco</Link>! Welcome to my hood.</div>