我到处都收到不确定的静态上下文,我错过了什么?路由器能否以某种方式影响它,或者我只是忘记了一些小部分。这个想法是定义用户浏览器,并在我所有组件中分配结果是非。谢谢
I am: eating
I am: eating a pine apple
export const GlobalContext = React.createContext(false);
class App extends Component {
static contextType = GlobalContext;
isBrowserChrome = () => {
return window.navigator.userAgent.indexOf('Chrome') !== -1;
};
render() {
return (
<GlobalProvider isChrome={this.isBrowserChrome()} >
<AppLayout>
<PageLayout>
<Loading/>
<PureModal/>
<ContentLayout>
<DashboardLayout>
{this.props.auth.authenticated && <EpMenu/> }
<div style={{marginTop: '20px'}}>
<Switch>
<Route exact path="/login/:token?" component={LoginPage}/>
<PrivateRoute exact path="/welcome" component={Welcome}/>
</Switch>
</div>
</DashboardLayout>
</ContentLayout>
</PageLayout>
</AppLayout>
</GlobalProvider>
);
}
}
App.contextType = GlobalContext;
export default App;
答案 0 :(得分:0)
您必须使用contextconsumer
来使用上下文值
请在以下链接中找到上下文API的参考: