expo / ex-navigator

Route-centric navigation built on top of React Native's Navigator
MIT License
522 stars 68 forks source link

Passing function to routes #58

Closed jasecoop closed 8 years ago

jasecoop commented 8 years ago

When using React I tend to pass functions as props into the children from their parent where they're called.

When I do this through ExNavigator, the function is undefined. E.g.

  render: function() {

    var route = Router.getStartRoute(this.props.handleLogin())

    return (
      <ExNavigator
        showNavigationBar={false}
        initialRoute={route}
        style={{ flex: 1 }}
        sceneStyle={{ paddingTop: 0 }}
      />
    )
  }

How do I call a function from a parent view with ExNavigator? I thought this was an important part of React, with state being kept in the parent as much as possible.

ide commented 8 years ago

The underlying Navigator API is imperative and stateful so it's good to go into this with the understanding that the component hierarchy here is not 100% reactive. Note the initialRoute prop: it is named that way since it's the route used for only the first render() pass. After that the route stack is controlled solely via imperative push/pop methods.

I don't fully understand your problem but could the issue be that you're invoking this.props.onLogin() instead of passing in the function?

jasecoop commented 8 years ago

I don't fully understand your problem but could the issue be that you're invoking this.props.onLogin() instead of passing in the function?

@ide that very well might be the case, how would I pass the function instead of invoking it?

ide commented 8 years ago

Change: Router.getStartRoute(this.props.handleLogin()) to Router.getStartRoute(this.props.handleLogin) ?