Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Parse navigation prop from component level to saga generator function via action payload

$
0
0

I am looking for ways to parse navigation prop from component level to saga generator function via action payload?

For example, I have the navigation prop inside my LoginScreen:

const LoginScreen: React.FC<Props> = navData => {  const navigateTo = (destinationScreen: string) =>    navData.navigation.navigate(destinationScreen);  const dispatch = useDispatch();  const submitHandler = (val: any, navigateTo: any) => {    dispatch(signInStart(val));  };

And then on my action, it would look like this:

export const signInStart = (userInput, navigateTo) => {  return {    type: type.SIGN_IN_START,    payload: userInput,  };};

And then inside my redux-saga function I will call it like this:

export function* onLogin({payload}) {  try {      const response = yield call(loginUserCall, payload);      if (response.data.user && response.data.token.api_token) {        console.log('response token >>>', response.data.token.api_token);        yield call(setToken(response.data.token.api_token));        navigateTo('DashboardScreen')      }    } else {     // do something    }  } catch (error) { // do something  } finally {     // do something  }}

Notice that I used navigateTo inside the redux-saga function. However, this did not work? is there a way to properly do this? are there any possible workaround?

PS. Already tried Navigating without the navigation prop using react navigation version 6 but no luck.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>