I want to make logged user's data global in my reactjs app. My App code:
class App extends Component {
getChildContext = () => {
return {
user: {
name: 'username',
email: '[email protected]'
}
}
}
render() {
return (
<Router>
<div>
<Route exact path='/game' component={Game} />
<Route exact path='/singup' component={Singup} />
</div>
</Router>
);
}
App.childContextTypes = {
user: PropTypes.object
};
In Game component I try to get use through this.context.user but I get undefined.
Can I propagate context to Router component?