Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we render same route using navigator in react native?

I have a view, lets say DynamicView. I am trying to push the same view(DynamicView)in navigator with different params.

this.props.navigator.push({
    component: DynamicView,
    params: {} //Different params
})
...
export default connect(mapStateToProps, mapDispatchToProps)(DynamicView)

DynamicView is connected with the redux flow. But I cannot access the latest state in the pushed component.

I want to know, whether is this the right thing to do? If yes, how can i access the latest state in the pushed component which is same as parent. If no, then is there any other approach to create the new route dynamically.

Any help is appreciated. Thanks.

React Native v0.40

like image 339
Dev Avatar asked Nov 09 '17 15:11

Dev


1 Answers

A React Navigation navigator, such as a StackNavigator for example, can easily support that. As confirmed here by the creator of React Navigation.

So say you're doing some basic navigation using a StackNavigator. You would do something like this:

export const SimpleApp = StackNavigator({
  MyDynamicView: { screen: DynamicView }
  ... other routes ...
});

And then, from your React components (including the DynamicView component) you can navigate to the MyDynamicView route as many times as you want, with different params:

navigation.navigate('MyDynamicView, { username: 'John' })

or

navigation.navigate('MyDynamicView, { username: 'John2' })
like image 141
idancali Avatar answered Oct 24 '22 11:10

idancali