React-native-router-flux: Use RNRF with redux-sagas

Created on 21 Feb 2017  路  3Comments  路  Source: aksonov/react-native-router-flux

Version

  • react-native-router-flux v3.37.0
  • react-native v0.41.2

Expected behaviour

I would like to be able to navigate by dispatching actions, so I can use RNRF with redux-sagas this way:

import {Actions as NavigationActions} from 'react-native-router-flux'

export function * login({username, password}) {
  const response = yield call(API.login, username, password)

  if (response.ok) {
    yield put(NavigationActions.mainScreen()) // <----- here
  }
  else {
    yield put(NavifationActions.errorScreen()) // <---- here
  }
}

Actual behaviour

calling NavigationActions.XXX() already calls dispatch. I would like to have the object it calls dispatch with so I could call yield put() it in my sagas.

Most helpful comment

I had a similar problem and at least for me using call instead of put did the job

So you'd do something like

import {Actions as NavigationActions} from 'react-native-router-flux'

export function * login({username, password}) {
  const response = yield call(API.login, username, password)

  if (response.ok) {
    yield call(NavigationActions.mainScreen) // <----- here
  }
  else {
    yield call(NavifationActions.errorScreen) // <---- here
  }
}

All 3 comments

I had a similar problem and at least for me using call instead of put did the job

So you'd do something like

import {Actions as NavigationActions} from 'react-native-router-flux'

export function * login({username, password}) {
  const response = yield call(API.login, username, password)

  if (response.ok) {
    yield call(NavigationActions.mainScreen) // <----- here
  }
  else {
    yield call(NavifationActions.errorScreen) // <---- here
  }
}

+1 do u have more examples on how saga works? like setting up the sagas

Thanks @holden-caulfield
@jjhesk, you should take a look at the official documentation of redux-sagas

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willmcclellan picture willmcclellan  路  3Comments

fgrs picture fgrs  路  3Comments

sreejithr picture sreejithr  路  3Comments

kirankalyan5 picture kirankalyan5  路  3Comments

sarovin picture sarovin  路  3Comments