Error boundaries should implement getDerivedStateFromError()

Viewed 14623

I was working on a project and everything was working fine, suddenly my app crashed because of this error :

Warning: %s: Error boundaries should implement getDerivedStateFromError(). 
In that method, return a state update to display an error message or fallback UI., RootErrorBoundary

The error is in these files :

* src/config/routes.js:31:27 in <unknown>
* src/modules/auth/actions.js:69:29 in <unknown>

in the line which contains _this.setState for routes.js :

componentDidMount() {
    let _this = this;
    store.dispatch(checkLoginStatus((isLoggedIn) => {
        _this.setState({isReady: true, isLoggedIn});
    }));
}

and in the line which contains callback(isLoggedIn) for actions.js :

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);
            }
        });
    };
}

please help me resolve this problem.

1 Answers
Related