Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Navigation V5 + Redux Saga: How can I navigate from the Saga?

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>
  );
};
like image 909
jefelewis Avatar asked Sep 04 '20 20:09

jefelewis


People also ask

How do I connect to Redux saga?

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.

How do I go back in react-navigation?

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.

How do I read Redux saga?

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.


1 Answers

you can use react-native Navigation-Service from saga.

https://reactnavigation.org/docs/navigating-without-navigation-prop/

like image 186
Tushar Pandey Avatar answered Oct 19 '22 07:10

Tushar Pandey