Issue:
React Navigation V5 + Redux Saga: How can I navigate from the Saga? I've tried using CommonActions.navigate()
, but that's not working. Am I missing something here?
I want to do all of the navigating through the saga incase something goes wrong in the saga, the user is not navigated to the screen.
React Navigation V5 Docs: CommonActions
Saga.js (Not Working):
// React Navigation: Sign Up
yield CommonActions.navigate('Sign Up');
Saga.js (Also Not Working):
// React Navigation: Sign Up
yield CommonActions.navigate({ name: 'Sign Up' });
AuthNavigator.js
// Auth Navigator
export const AuthNavigator = () => {
return (
<AuthStack.Navigator initialRouteName="Login">
<AuthStack.Screen
name="Login"
component={Login}
options={{
headerShown: false,
}}
/>
<AuthStack.Screen
name="Sign Up"
component={SignUp}
options={{
headerShown: false,
}}
/>
<AuthStack.Screen
name="Sign Up Confirm"
component={SignUpConfirm}
options={{
headerShown: false,
}}
/>
<AuthStack.Screen
name="Forgot Password"
component={ForgotPassword}
options={{
headerShown: true,
title: '',
}}
/>
<AuthStack.Screen
name="Terms & Conditions"
component={TermsAndConditions}
options={{
headerShown: false,
}}
/>
</AuthStack.Navigator>
);
};
First we import our Saga from the ./sagas module. Then we create a middleware using the factory function createSagaMiddleware exported by the redux-saga library. Before running our helloSaga , we must connect our middleware to the Store using applyMiddleware . Then we can use the sagaMiddleware.
The header bar will automatically show a back button, but you can programmatically go back by calling navigation. goBack() . On Android, the hardware back button just works as expected. You can go back to an existing screen in the stack with navigation.
Redux Saga is a middleware library used to allow a Redux store to interact with resources outside of itself asynchronously. This includes making HTTP requests to external services, accessing browser storage, and executing I/O operations. These operations are also known as side effects.
you can use react-native Navigation-Service from saga.
https://reactnavigation.org/docs/navigating-without-navigation-prop/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With