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

Commit fcbe308

Browse files
committed
Make key optional
Fixes #65
1 parent 7cd0425 commit fcbe308

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,28 @@ class Root extends React.Component {
8989

9090
```js
9191
function createReactNavigationReduxMiddleware<State: {}>(
92-
key: string,
9392
navStateSelector: (state: State) => NavigationState,
93+
key?: string,
9494
): Middleware<State, *, *>;
9595
```
9696

9797
* Returns a middleware that can be applied to a Redux store.
98-
* Param `key` needs to be unique for the Redux store. Most people only have one store, so can use any string (eg. `"root"`), as long as it's consistent with the call to `createReduxContainer` below.
9998
* Param `navStateSelector` selects the navigation state from your store.
99+
* Param `key` needs to be unique for the Redux store and consistent with the call to `createReduxContainer` below. You can leave it out if you only have one store.
100100

101101
### `createReduxContainer` (required)
102102

103103
```js
104104
function createReduxContainer(
105105
navigator: Navigator,
106-
key: string,
106+
key?: string,
107107
): React.ComponentType<{ state: NavigationState, dispatch: Dispatch }>;
108108
```
109109

110110
* Returns a HOC (higher-order component) that wraps your root navigator.
111111
* `createReactNavigationReduxMiddleware` must be called before this one!
112112
* Param `navigator` is your root navigator (React component).
113-
* Param `key` needs to be consistent with the call to `createReactNavigationReduxMiddleware` above.
113+
* Param `key` needs to be consistent with the call to `createReactNavigationReduxMiddleware` above. You can leave it out if you only have one store.
114114
* Returns a component to use in place of your root navigator. Pass it `state` and `dispatch` props that you get via `react-redux`'s `connect`.
115115

116116
### `createNavigationReducer` (optional)

index.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ declare module 'react-navigation-redux-helpers' {
1414

1515
export type ReducerState = NavigationState | null | undefined;
1616

17-
export function createReactNavigationReduxMiddleware<S>
18-
(key: string, navStateSelector: (state: S) => NavigationState): Middleware;
17+
export function createReactNavigationReduxMiddleware<S>(
18+
navStateSelector: (state: S) => NavigationState,
19+
key?: string,
20+
): Middleware;
1921

2022
export function createNavigationReducer(navigator: Navigator): Reducer<ReducerState>;
2123

2224
export function createReduxContainer<S, P>(
2325
navigator: Navigator,
24-
key: string,
26+
key?: string,
2527
): React.ComponentType<{ state: NavigationState; dispatch: NavigationDispatch } & P>;
2628
}

src/create-redux-container.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function createReduxContainer<State: NavigationState, Props: RequiredProps<State
2828
*,
2929
$Diff<Props, RequiredProps<State>>,
3030
>,
31-
key: string,
31+
key?: string = "root",
3232
): React.ComponentType<Props> {
3333
const didUpdateCallback = createDidUpdateCallback(key);
3434
const propConstructor = createNavigationPropConstructor(key);

src/middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const EMPTY_SCREEN_PROPS = {};
2323
const getScreenProps = () => EMPTY_SCREEN_PROPS;
2424

2525
function createReactNavigationReduxMiddleware<State: {}>(
26-
key: string,
2726
navStateSelector: (state: State) => NavigationState,
27+
key?: string = "root",
2828
): Middleware<State, *, *> {
2929
reduxSubscribers.set(key, new Set());
3030
return store => next => action => {

0 commit comments

Comments
 (0)