Skip to content

Commit 9961062

Browse files
azizhktimdorr
authored andcommitted
Add createProvider Documentation. (#752)
* Add createProvider docs * Add storeKey to connect options * italics * Update api.md * Add you probably only need this
1 parent a9bb9d3 commit 9961062

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/api.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ It does not modify the component class passed to it; instead, it *returns* a new
7878
* [`areOwnPropsEqual`] *(Function)*: When pure, compares incoming props to its previous value. Default value: `shallowEqual`
7979
* [`areStatePropsEqual`] *(Function)*: When pure, compares the result of `mapStateToProps` to its previous value. Default value: `shallowEqual`
8080
* [`areMergedPropsEqual`] *(Function)*: When pure, compares the result of `mergeProps` to its previous value. Default value: `shallowEqual`
81+
* [`storeKey`] *(String)*: The key of the context from where to read the store. You probably only need this if you are in the inadvisable position of having multiple stores. Default value: `'store'`
8182

8283
<a id="connect-arguments-arity"></a>
8384
##### The arity of mapStateToProps and mapDispatchToProps determines whether they receive ownProps
@@ -384,3 +385,41 @@ function selectorFactory(dispatch) {
384385
export default connectAdvanced(selectorFactory)(TodoApp)
385386
```
386387

388+
<a id="createProvider"></a>
389+
### `createProvider([storeKey])`
390+
391+
Creates a new `<Provider>` which will set the Redux Store on the passed key of the context. You probably only need this if you are in the inadvisable position of having multiple stores. You will also need to pass the same `storeKey` to the `options` argument of [`connect`](#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options)
392+
393+
<a id="createProvider-arguments"></a>
394+
#### Arguments
395+
396+
* [`storeKey`] (*String*): The key of the context on which to set the store. Default value: `'store'`
397+
398+
#### Examples
399+
Before creating multiple stores, please go through this FAQ: [Can or should I create multiple stores?](http://redux.js.org/docs/faq/StoreSetup.html#can-or-should-i-create-multiple-stores-can-i-import-my-store-directly-and-use-it-in-components-myself)
400+
401+
```js
402+
import {connect, createProvider} from 'react-redux'
403+
404+
const STORE_KEY = 'componentStore'
405+
406+
export const Provider = createProvider(STORE_KEY)
407+
408+
function connectExtended(
409+
mapStateToProps,
410+
mapDispatchToProps,
411+
mergeProps,
412+
options = {}
413+
) {
414+
options.storeKey = STORE_KEY
415+
return connect(
416+
mapStateToProps,
417+
mapDispatchToProps,
418+
mergeProps,
419+
options
420+
)
421+
}
422+
423+
export {connectExtended as connect}
424+
```
425+
Now you can import the above `Provider` and `connect` and use them.

0 commit comments

Comments
 (0)