【发布时间】:2019-05-27 05:46:55
【问题描述】:
我正在做一个项目,一切正常,突然我的应用因为这个错误而崩溃:
Warning: %s: Error boundaries should implement getDerivedStateFromError().
In that method, return a state update to display an error message or fallback UI., RootErrorBoundary
错误在这些文件中:
* src/config/routes.js:31:27 in <unknown>
* src/modules/auth/actions.js:69:29 in <unknown>
在包含 _this.setState for routes.js 的行中:
componentDidMount() {
let _this = this;
store.dispatch(checkLoginStatus((isLoggedIn) => {
_this.setState({isReady: true, isLoggedIn});
}));
}
并且在包含 actions.js 的回调(isLoggedIn)的行中:
export function checkLoginStatus(callback) {
return (dispatch) => {
auth.onAuthStateChanged((user) => {
let isLoggedIn = (user !== null);
if (isLoggedIn) {
//get the user object from the Async storage
AsyncStorage.getItem('user', (err, user) => {
if (user === null) isLoggedIn = false //set the loggedIn value to false
else dispatch({type: t.LOGGED_IN, data: JSON.parse(user)})
callback(isLoggedIn);
});
} else {
dispatch({type: t.LOGGED_OUT});
callback(isLoggedIn);
}
});
};
}
请帮我解决这个问题。
【问题讨论】:
-
您的应用程序(即
rootErrorBoundary)的某处(可能靠近根目录)是否有/使用了错误边界组件?它是否实现getDerivedStateFromError?在最近的一次更新中,React 的 errorBoundary 接口发生了一些变化。可以包含rootErrorBoundary的代码吗? -
不,我没有任何 rootErrorBoundary 的代码。
-
现在我在同一行出现另一个错误:不变违规:此导航器缺少导航道具
-
嗯,你的action.js中有两行
callback(isLoggedIn);,你知道哪个被调用了吗?传递的isLoggedIn的值是多少?您可以发布与您现在看到的新错误相关的代码吗? -
错误与之前的行相同。但我不知道它现在是如何工作的。我什么都没改变,但现在一切正常。
标签: javascript firebase react-native firebase-authentication