Skip to content

Add createProvider Documentation. #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ It does not modify the component class passed to it; instead, it *returns* a new
* [`areOwnPropsEqual`] *(Function)*: When pure, compares incoming props to its previous value. Default value: `shallowEqual`
* [`areStatePropsEqual`] *(Function)*: When pure, compares the result of `mapStateToProps` to its previous value. Default value: `shallowEqual`
* [`areMergedPropsEqual`] *(Function)*: When pure, compares the result of `mergeProps` to its previous value. Default value: `shallowEqual`
* [`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'`

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

<a id="createProvider"></a>
### `createProvider([storeKey])`
Copy link
Contributor Author

@azizhk azizhk Jul 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to add subKey as well, but then over here:
https://github.com/reactjs/react-redux/blob/a9bb9d3b074eb04f4d7922e22fce733beb148650/src/components/connectAdvanced.js#L78
It is hardcoded to be

const subscriptionKey = storeKey + 'Subscription'

So I don't think I could pass it in connect so it was broken anyways

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should fix that...


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)

<a id="createProvider-arguments"></a>
#### Arguments

* [`storeKey`] (*String*): The key of the context on which to set the store. Default value: `'store'`

#### Examples
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)

```js
import {connect, createProvider} from 'react-redux'

const STORE_KEY = 'componentStore'

export const Provider = createProvider(STORE_KEY)

function connectExtended(
mapStateToProps,
mapDispatchToProps,
mergeProps,
options = {}
) {
options.storeKey = STORE_KEY
return connect(
mapStateToProps,
mapDispatchToProps,
mergeProps,
options
)
}

export {connectExtended as connect}
```
Now you can import the above `Provider` and `connect` and use them.