React-native-router-flux: switching screen inside componentDidMount lifecycle

Created on 20 Oct 2018  路  2Comments  路  Source: aksonov/react-native-router-flux

hey everyone, I'm new to RNRF and everything seem easy so far, I just have one issue,
here is my Scenes

const App = () => (
  <Router>
    <Scene key="root">
      <Scene
        key="InitialScreen"
        component={InitialScreen}
        title="First screen"
        initial
      />
      <Scene
        key="main"
        component={Main}
        title="Main"
      />
    </Scene>
  </Router>
);

inside InitialScreen

export default compose(
  lifecycle({
    componentDidMount() {
      Actions.popTo('main');
      // tryed also Actions.main() also didn't work
    },
  }),
)(InitialScreen);

my plan is to check some props over there and then to navigate to correct screen, but for some reason it doesn't work the screen remains on InitialScreen, I tried to use Actions.main() as a fn for clicking a button and then it works but inside a lifecycle (like componentDidMount / componentWillMount) it doesn't. not sure what I'm missing here.

thanks!

Version

  • react-native-router-flux v4.0.5
  • react v16.6.0-alpha.8af6728
  • react-native v0.57.3

Most helpful comment

setTimeout (even with zero delay) is necessary because of async react-native architecture

All 2 comments

I just faced similar issue
https://github.com/RNRF/react-native-router-flux/issues/3302

The answer seemed a bit weird to me, let's say that's the only solution so what's count as a safe and minimal amount to pass to setTimeout.

Thanks.

setTimeout (even with zero delay) is necessary because of async react-native architecture

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sreejithr picture sreejithr  路  3Comments

booboothefool picture booboothefool  路  3Comments

rafaelcorreiapoli picture rafaelcorreiapoli  路  3Comments

fgrs picture fgrs  路  3Comments

xnog picture xnog  路  3Comments