Below is my reducer code.
import * as Helper from '../utils/helper';
import AppNavigator from "../Navigation/navigationStack";
const initialState = { user: "" };
export function pedagogyReducer(state = initialState, action){
switch (action.type) {
case 'REGISTER':{
state = {
...state,
user: action.newUser,
showError: action.showError ? action.showError : false,
errorMessage: action.errorMessage ? action.errorMessage: "",
}
console.log(action.showError);
{
////////here I want to redirect to login if response if success else want to show error message
}
if(!action.showError){
AppNavigator.router.getStateForAction(
AppNavigator.router.getActionForPathAndParams("Login")
);
return state;
} else {
return state;
}
break;
}
default:
return state;
}
}
export default pedagogyReducer;
I am not sure should I redirect to success/error screen from reducer or from other file. I have used reducer, action, middleware(fetch APIs) and react-navigation.