You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -85,6 +84,8 @@ Passing action creator functions as the second parameter will bind them to the s
85
84
86
85
Why don’t we bind action creators to a store right away? This is because of the so-called “universal” apps that need to render on the server. They would have a different store instance for every request, so we don’t know the store instance during the definition!
Whether to put `connect()` call in the same file as the “dumb” component, or separately, is up to you.
111
+
Ask yourself whether you'd want to reuse this component but bind it to different data, or not.
112
+
109
113
### Usage Notes
110
114
111
115
You can have many `connect()`-ed components in your app at any depth, and you can even nest them. It is however preferable that you try to only `connect()` top-level components such as route handlers, so the data flow in your application stays predictable.
@@ -125,7 +129,7 @@ Don’t forget decorators are experimental! And they desugar to function calls a
125
129
126
130
### Additional Flexibility
127
131
128
-
This the most basic usage, but `connect()` supports many other different patterns: just passing the vanilla `dispatch()` function down, binding multiple action creators, putting them as `actions` prop, selecting parts of state and binding action creators depending on `props`, and so on. Check out [Recipes](#recipes) for some ideas about advanced `connect()` usage.
132
+
This the most basic usage, but `connect()` supports many other different patterns: just passing the vanilla `dispatch()` function down, binding multiple action creators, putting them as `actions` prop, selecting parts of state and binding action creators depending on `props`, and so on. Check out `connect()` docs below to learn more.
Returns a component class that injects the Redux Store’s `dispatch` as a prop into `Component` so it can dispatch Redux actions.
179
-
180
-
The returned component also subscribes to the updates of Redux store. Any time the state changes, it calls the `mapState` function passed to it. It is called a **selector**. The selector function takes a single argument of the entire Redux store’s state and returns an object to be passed as props. Use [reselect](https://github.com/faassen/reselect) to efficiently compose selectors and memoize derived data.
181
-
182
-
Both `dispatch` and every property returned by `mapState` will be provided to your `Component` as `props`.
180
+
### `<Provider store>`
183
181
184
-
It is the responsibility of a Smart Component to bind action creators to the given `dispatch` function and pass those
185
-
bound creators to Dumb Components. Redux provides a `bindActionCreators` to streamline the process of binding action
186
-
creators to the dispatch function.
182
+
Makes Redux store available to the `connect()` calls in the component hierarchy below.
183
+
You can’t use `connect()` without wrapping the root component in `<Provider>`.
187
184
188
-
**To use `connect()`, the root component of your app must be wrapped into `<Provider>{() => ... }</Provider>` before being rendered.**
185
+
#### Props
189
186
190
-
See the usage example in the quick start above.
187
+
*`store`: (*[Redux Store](http://gaearon.github.io/redux/docs/api/Store.html)*): The single Redux store in your application.
188
+
*`children`: (*Function*): Unlike most React components, `<Provider>` accepts a [function as a child](#child-must-be-a-function) with your root component. This is a temporary workaround for a React 0.13 context issue, which will be fixed when React 0.14 comes out.
191
189
192
-
###`<Provider store>`
190
+
#### Example
193
191
194
192
```js
195
193
// Make store available to connect() below in hierarchy
196
-
<Provider store={store}>
197
-
{() =><MyRootComponent>}
198
-
</Provider>
194
+
React.render(
195
+
<Provider store={store}>
196
+
{() =><MyRootComponent>}
197
+
</Provider>,
198
+
rootEl
199
+
);
199
200
```
200
201
201
-
The `Provider` component takes a `store` prop and a [function as a child](#child-must-be-a-function) with your root
202
-
component. The `store` is then passed to the child via React's `context`. This is the entry point for Redux and must be
*[`mapState`] (*Function*): If specified, the component will subscribe to Redux store updates. Any time it updates, `mapState` will be called. Its result must be a plain object, and it will be merged into the component’s props. If you omit it, the component will not be subscribed to the Redux store.
209
+
210
+
*[`mapDispatch`] (*Object* or *Function*): If an object is passed, each function inside it will be assumed to be a Redux action creator, and an object with the same function names, but bound to a Redux store, will be merged into the component’s props. If a function is passed, it will be given `dispatch`. It’s up to you to return an object that somehow uses `dispatch` to bind action creators in your own way. (Tip: you may use `bindActionCreators` helper from Redux.) If you pass omit it, the default implementation just injects `dispatch` into your component’s props.
211
+
212
+
*[`mergeProps`] (*Function*): If specified, it is passed the result of `mapState()`, `mapDispatch()`, and the parent `props`. The plain object you return from it will be passed as props to the wrapped component. You may specify this function to select a slice of the state based on props, or to bind action creators to a particular variable from props. If you omit it, `{ ...props, ...mapStateResult, ...mapDispatchResult }` is used by default.
213
+
214
+
#### Returns
215
+
216
+
A React component class that injects state and action creators into your component according to the specified options.
217
+
218
+
#### Remarks
219
+
220
+
* The `mapState` function takes a single argument of the entire Redux store’s state and returns an object to be passed as props. It is often called a **selector**. Use [reselect](https://github.com/faassen/reselect) to efficiently compose selectors and [compute derived data](http://gaearon.github.io/redux/docs/recipes/ComputingDerivedData.html).
221
+
222
+
***To use `connect()`, the root component of your app must be wrapped into `<Provider>{() => ... }</Provider>` before being rendered.**
204
223
205
-
##Recipes
224
+
#### Examples
206
225
207
226
##### Inject just `dispatch` and don't listen to store
0 commit comments