Expose params as regular props
Levi Buzolic
You can access somewhat directly with
navigation.state.params
however the getParam()
method will handle edge cases like undefined param object and gives convenience methods for handling defaults.As others have said, exposing them directly as flat props can lead to unexpected collisions with defined props.
If you really wanted to have this behaviour, you can use your own higher order component:
function withNavigationProps(WrappedComponent) {
return function WithNavigationProps(props) {
return <WrappedComponent {...props.navigation.state.params} {...props} />;
}
}
Sébastien Lorber
You can already wrap all your screens with a HOC which would permit to expose only the navigation stuff you want instead of the whole navigation prop
Eddie Cooro
Getting params directly from the props would cause collisions in param names.