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
Returns a component class that injects the Redux Store’s `dispatch` as a prop into `Component` so it can dispatch Redux actions.
223
+
224
+
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.
225
+
226
+
Both `dispatch` and every property returned by `mapState` will be provided to your `Component` as `props`.
227
+
228
+
It is the responsibility of a Smart Component to bind action creators to the given `dispatch` function and pass those
229
+
bound creators to Dumb Components. Redux provides a `bindActionCreators` to streamline the process of binding action
230
+
creators to the dispatch function.
231
+
232
+
**To use `connect()`, the root component of your app must be wrapped into `<Provider>{() => ... }</Provider>` before being rendered.**
233
+
234
+
See the usage example in the quick start above.
235
+
236
+
### `<Provider store>`
237
+
238
+
```js
239
+
// Make store available to connect() below in hierarchy
240
+
<Provider store={store}>
241
+
{() =><MyRootComponent>}
242
+
</Provider>
243
+
```
244
+
245
+
The `Provider` component takes a `store` prop and a [function as a child](#child-must-be-a-function) with your root
246
+
component. The `store` is then passed to the child via React's `context`. This is the entry point for Redux and must be
247
+
present in order to use the `connect` component.
248
+
249
+
## Recipes
250
+
221
251
```js
222
252
// Inject just `dispatch` and don't listen to store
223
253
exportdefaultconnect()(TodoApp);
224
254
255
+
225
256
// Inject `dispatch` and every field in the global state (SLOW!)
226
257
exportdefaultconnect(state=> state)(TodoApp);
227
258
259
+
228
260
// Inject `dispatch` and `todos`
229
261
functionmapState(state) {
230
262
return { todos:state.todos };
231
263
}
264
+
232
265
exportdefaultconnect(mapState)(TodoApp);
233
266
267
+
234
268
// Inject `todos` and all action creators (`addTodo`, `completeTodo`, ...)
Returns a component class that injects the Redux Store’s `dispatch` as a prop into `Component` so it can dispatch Redux actions.
319
-
320
-
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.
321
-
322
-
Both `dispatch` and every property returned by `mapState` will be provided to your `Component` as `props`.
323
-
324
-
It is the responsibility of a Smart Component to bind action creators to the given `dispatch` function and pass those
325
-
bound creators to Dumb Components. Redux provides a `bindActionCreators` to streamline the process of binding action
326
-
creators to the dispatch function.
327
-
328
-
**To use `connect()`, the root component of your app must be wrapped into `<Provider>{() => ... }</Provider>` before being rendered.**
329
-
330
-
See the usage example in the quick start above.
331
-
332
-
### `<Provider store>`
333
374
334
-
```js
335
-
// Make store available to connect() below in hierarchy
0 commit comments