【问题标题】:Error boundaries should implement getDerivedStateFromError()错误边界应该实现 getDerivedStateFromError()
【发布时间】: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


【解决方案1】:

我通过清除应用数据解决了这个问题

【讨论】:

  • 您能否详细说明您遇到的具体情况以及您为解决问题所采取的步骤?也许对于正在寻找解决方案但不熟悉设置并且可能对清除应用数据的含义感到困惑的人?
猜你喜欢
  • 1970-01-01
  • 2016-07-11
  • 2014-08-13
  • 1970-01-01
  • 2023-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-15
相关资源
最近更新 更多