【发布时间】:2020-11-03 01:34:09
【问题描述】:
我的 App.js 中的所有路由都是这样的:
<Route exact path="/" component={Home} />
<Route path="/explore" component={Explore} />
<Route path="/register" component={Register} />
<ProtectedRoute path="/create" component={CreatePost} />
我想将一个成功/错误警报组件切换为反馈,但我想在整个应用程序上方显示它,无论现在呈现哪个组件。所以我被卡住了,不知道最好的方法是什么。我尝试编写一个函数来切换 App.js 中的警报并将其导出,但我无法导入它并更改状态。
onShowAlert = () => {
this.setState({ showAlert: true };
};
【问题讨论】:
标签: javascript reactjs web state