Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

bindActionCreators to navigation prop #12

Closed
kodayashi opened this issue Mar 3, 2018 · 3 comments
Closed

bindActionCreators to navigation prop #12

kodayashi opened this issue Mar 3, 2018 · 3 comments

Comments

@kodayashi
Copy link

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
Copy link
Member

Ashoat commented Mar 4, 2018

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
Copy link
Member

Ashoat commented Mar 5, 2018

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

@Ashoat Ashoat closed this as completed Mar 5, 2018
@kodayashi
Copy link
Author

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants