Answer the question
In order to leave comments, you need to log in
How to pass props to a component?
Hey!
See, I'm using props. How can I pass the same props to the Menu component?render={props => <Home {...props}/>}
class App extends Component {
render() {
return (
<div className="App">
<Menu/>
<main>
<Switch>
<Route exact path="/" render={props => <Home {...props}/>}/>
<Route path="/contacts" render={props => <Contacts {...props}/> }/>
</Switch>
</main>
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
Something like this.
import { withRouter } from 'react-router-dom';
const Menu = () => { ... }
export default withRouter(Menu);
<Route exact path="/" component={Home} />
<Route path="/contacts" component={Contacts} />
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question