react-native-router-flux: Actions.callback is not defined!

Version

  • react-native-router-flux v3.22.8
  • react-native v0.24.0-rc5

Issue

I’d expect that as soon as the Router is rendered, Actions has a callback for all scenes to transition to.

In my app I tried to transition to a login scene if the user isn’t logged in at start. However, I get an error as soon as Actions.login() in the componentDidMount() function is executed:

Actions.callback is not defined!

If I try to do the same from within the Main.componentDidMount() function it works as expected.

At which point are the Scene callbacks added to Actions? Am I doing it wrong?

const reducerCreate = params => {
  const defaultReducer = Reducer(params);
  return (state, action) => {
    console.log('ACTION:', action);
    return defaultReducer(state, action);
  };
};
componentDidMount() {
  if (!loggedIn()) {
    Actions.login();
  }
},
render() {
  return (
    <Router createReducer={reducerCreate}>
      <Scene key="root" hideNavBar>
        <Scene key="login" component={Login} />
        <Scene key="main" component={Main} initial />
      </Scene>
    </Router>
  );
}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 31 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Is this fixed? I don’t understand what I should do to get over this? Where is the right spot to call Actions.methods… ? If not in componentDidMount? where?

Thanks Much

@shilpan the callback is an excellent idea. Or a promise would work too. And yes, I’m using an arbitrary timeout as well (1 second). Obviously far from ideal.