First of all, I would explain that I'm using react-native with typescript and hooks and for redux I'm using saga.
I have a button in a component that send a code to api to validate it. If it success saga will update some values of stored data and component will change the page. Therfore, I need a callback or somthing like this to ensure in the component that the process works correctly and can change the page.
Action of validate
export function validationCode(code: string) { return { type: type.VALIDATE_CODE, payload: {code} }}
Submit function in component:
function submitValidation(): void{ dispatch(validationCode(code)); //TODO get callback or somthing to know if works correctly //if(works) NavigationService.pop();}
Sagas file
function* fetchValidation(action: any) { try{ yield put(loading(true)) let response:any = yield* call(validationCodeService.validate, action.payload.code); yield put(setValidCode(true)) yield put(loading(false)) //CALLBACK SUCCESS? }catch(e){ yield put(setAlert({state: true, show: true, message: "Error on validation", type: 'error'})); //CALLBACK ERROR? console.warn(e); yield put(loading(false)) }}