Answer the question
In order to leave comments, you need to log in
How to make sure that the preloader is shown when loading?
How to correctly implement the display of the preloader during the request?
Initially, I did it without middleware, everything was simple there:
const onSubmitSecurityQuestion = async () => {
setLoading(true);
await saveSecurityQuestion(dispatch, {
question,
answer,
repeatAnswer,
...(yourQuestion ? { yourQuestion } : {}),
});
setLoading(false);
};
export const saveSecurityQuestion = (dispatch, data = null) => {
try {
const saveSecurityQuestionResult = await callSecurityQuestion(data)
.then((response) => get(response, 'data', null))
.catch((e) => throwError(getError(e)));
console.log('saveSecurityQuestionResult', saveSecurityQuestionResult);
// throwError();
} catch (error) {
dispatch(
setError({
code: get(error, 'code', null),
message: get(error, 'message', null),
})
);
}
};
const [loading, setLoading] = useState(false);
const onSubmitSecurityQuestion = () => {
setLoading(true);
dispatch(
saveSecurityQuestion({
question,
answer,
repeatAnswer,
...(yourQuestion ? { yourQuestion } : {}),
})
);
setLoading(false);
};
export const saveSecurityQuestion =
(data = null) =>
async (dispatch) => {
try {
const saveSecurityQuestionResult = await callSecurityQuestion(data)
.then((response) => get(response, 'data', null))
.catch((e) => throwError(getError(e)));
console.log('saveSecurityQuestionResult', saveSecurityQuestionResult);
// throwError();
} catch (error) {
dispatch(
setError({
code: get(error, 'code', null),
message: get(error, 'message', null),
})
);
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question