connected-react-navigation
Redux binding for React Navigation v5
Installation
yarn add react-navigation-redux-binding
Usage
Step 1
Create a new instance of NavigationService
from 'react-navigation-redux-binding'
//... const navigationService =
Step 2
Add navigationService.navigationMiddleware
to the store middleware so that we can dispatch navigate('ScreenName')
action
const store =
Step 3
Set the navigationService.navigationRef
to NavigationContainer
component's ref
<NavigationContainer ref=navigationServicenavigationRef> /* ... */</NavigationContainer>
And Voila! (Step 4)
Dispatch navigate action
const login = { return async { await // This will dispatch navigation via the middleware }}
Limitation
Navigate can only use the screen name.
Passing the navigation params
has not been implemented yet.
Background story
When I was working on a react native application I had to navigate to different screen from redux action which was sometime also asynchronous. So inspired by connected-react-router, I implemented a service binding for redux and react navigation v5 in my application. Then extracted the code into this library.