react-navigation / redux-helpers

Redux middleware and utils for React Navigation
Other
296 stars 43 forks source link

bindActionCreators to navigation prop #12

Closed kodayashi closed 6 years ago

kodayashi commented 6 years ago

When doing this: <AppNavigator navigation={addNavigationHelpers({ dispatch, state: nav, addListener, ...bindActionCreators(ActionCreators, dispatch), })} />

I would expect my action creators from ActionCreators to be bound to the navigation property, however they are not. The idea would be to use navigation.someCustomNavigationActionCreator() as opposed to binding navigation-related action creators to the AppNavigator Component itself (in which case I would be following the typical action creator flow of just calling someNavigationActionCreator().

I'm attempting this because I would prefer to follow the pattern of not explicitly using dispatch in my containers, which is how the documented example here is doing it: https://reactnavigation.org/docs/redux-integration.html

Is there not support for binding navigation-related action creators directly to the navigation prop? If so, am I doing something wrong here?

Thanks!

Ashoat commented 6 years ago

Unfortunately there isn’t support for this now. The reason those action creators get dropped is because the code constructs “child” navigation props for child screens and navigators that have the state property set to the specific route. This code doesn’t bother to preserve all the navigation prop’s properties when making child navigation props, so your custom action creators get dropped.

Do you think we should support something like this? If so we would have to change the code in some places, so this would require a PR or an RFC on the main react-navigation package.

Sorry for bouncing you around between places. cc @brentvatne

Ashoat commented 6 years ago

Let's track this on this issue in the main repo

kodayashi commented 6 years ago

Hey @Ashoat - IMO it would be cool to add support for binding additional action creators with the navigation prop to remove needing to use dispatch (per some of the best practices out there I've read like http://blog.isquaredsoftware.com/2016/10/idiomatic-redux-why-use-action-creators/).

Happy to move the discussion back to react-navigation, thanks!