In order to use await
, the function directly enclosing it needs to be async. According to your comment, adding async
to the inner function fixes your issue, so I'll post that here:
export const sendVerificationEmail = async () =>
async (dispatch) => {
try {
dispatch({ type: EMAIL_FETCHING, payload: true });
await Auth.sendEmailVerification();
dispatch({ type: EMAIL_FETCHING, payload: false }))
} catch (error) {
dispatch({ type: EMAIL_FETCHING, payload: false });
throw new Error(error);
}
};
Possibly, you could remove the async
from the outer function because it does not contain any asynchronous operations, but that would depend on whether the caller of that sendVerificationEmail
is expecting sendVerificationEmail
to return a promise or not.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…