javascript - 为每个页面设置一个状态变量
问题描述
在每一页上,我都执行此功能:
import * as sync_helper from '../utils/sync';
componentWillUnmount() { this._isMounted = false; }
componentDidMount() {
this._isMounted = true;
sync_helper.getLocal().then((l) => {
if(this._isMounted)
this.setState({ current_user: l.current_user,loaded: true });
});
}
我有时也有更多的异步函数,componentDidMount()
但这个在每一页中。
有没有办法自动将我添加current_user
到每个状态而不将其放在每个页面上?
我正在使用反应导航(堆栈)
解决方案
推荐阅读
- python - 如果 unicode 仅在 ascii 中,我可以使用 str() 将 unicode 转换为 python 中的字符串吗?
- marklogic - 在 MarkLogic 中设置最大森林大小的任何参数?
- python - 有没有办法在构建 Conda 包时同时使用构建字符串和构建号
- c++ - 错误:没有匹配的函数调用'function namel'
- angular - sqllite ionic 2 无法读取未定义的属性推送
- css - 垂直拆分弹出框内容
- c - 复制字符的指针问题
- css - Bootstrap 4 Div 排序问题
- c# - 将 XML 发布到 MVC 控制器 C#
- python - 为什么 numpy 比我的 c/c++ 代码对浮点数组求和更快?