Pavle Lekic
Pavle Lekic

Reputation: 1122

Navigator, passing props to current scene?

I'm using https://github.com/exponentjs/ex-navigator, which is built on top of RN Navigator, is there a way to pass/set props for all scenes, like without writing this manually for every scene? If I have 50 scenes, and I want some property to pass down to all scenes?

This is the situation, I have a top level component (above navigator), that is supposed to pass props to navigator, and I want navigator to pass those props down to whatever scene is currently displayed. Is that possible?

Thanks.

Upvotes: 0

Views: 89

Answers (1)

BradByte
BradByte

Reputation: 11093

Yes, that is possible. You can simply pass those props into the rendered scene. You could try something like this...

renderScene={(route, navigator) => {
             // in my implementation, I pass the component as a prop of route.
             let RoutedComponent = route.component

             // you can pass props into the route itself, or pass down arbitrary props from the parent component
             return (
                <RoutedComponent navigator={navigator} {this.props.somePropFromParent} {...route.props}/>
             )
}}

Upvotes: 2

Related Questions