React Native - [unhandled Promise Rejection: Error: Signup Error]
I get this intentional error because I'm using the same email to register. It says I'm not handling the rejection; can someone explain why because I have a .catch() which should ca
Solution 1:
I'm not 100% sure of this since i'm used to try catch, but it could be because you are not actually handling the promise rejection:
in your then
.then((res) => {
if (!res.ok) {
thrownewError("Signup Error");
} else {
const resData = res.json();
return resData;
}
}, (reject) => {
// handle this
})
Solution 2:
dispatch is a synchronous method in redux and in try catch
you used async await
which is asynchronous
what you can do is adding a asynchronous dispatch middleware to your redux store
constasyncDispatchMiddleware = (store) => (next) =>(action) => {
let syncActivityFinished = false;
let actionQueue = [];
functionflushQueue() {
actionQueue.forEach((a) => store.dispatch(a)); // flush queue
actionQueue = [];
}
functionasyncDispatch(asyncAction) {
actionQueue = actionQueue.concat([asyncAction]);
if (syncActivityFinished) {
flushQueue();
}
}
const actionWithAsyncDispatch = Object.assign({}, action, { asyncDispatch });
next(actionWithAsyncDispatch);
syncActivityFinished = true;
flushQueue();
};
now you can make in promise scheme the asyncDispatch
method
Post a Comment for "React Native - [unhandled Promise Rejection: Error: Signup Error]"