Skip to content

Commit 2c05077

Browse files
committed
Add example to API docs for no-subscribe actions
In a recent project, I needed a container component that had access to a few actions, but it didn't need to subscribe to the store. The component was just a button that performed an action; it didn't care about what the state of the app was. The docs for `connect` don't have an example for how to omit the `mapStateToProps` argument, while still providing a value for `mapDispatchToProps`. I'm not entirely sure if this is the best way to accomplish that goal, so please do let me know if there's a better/simpler way! I tried simply passing a single `mapDispatchToProps` argument, but it was interpreted as the `mapStateToProps` param.
1 parent 93cdfae commit 2c05077

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docs/api.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ Returns the wrapped component instance. Only available if you pass `{ withRef: t
106106
export default connect()(TodoApp)
107107
```
108108

109+
##### Inject all action creators (`addTodo`, `completeTodo`, ...) without subscribing to the store
110+
111+
```js
112+
import * as actionCreators from './actionCreators'
113+
114+
export default connect(null, actionCreators)(TodoApp)
115+
```
116+
109117
##### Inject `dispatch` and every field in the global state
110118

111119
>Don’t do this! It kills any performance optimizations because `TodoApp` will rerender after every action.
@@ -126,7 +134,7 @@ function mapStateToProps(state) {
126134
export default connect(mapStateToProps)(TodoApp)
127135
```
128136

129-
##### Inject `todos` and all action creators (`addTodo`, `completeTodo`, ...)
137+
##### Inject `todos` and all action creators
130138

131139
```js
132140
import * as actionCreators from './actionCreators'

0 commit comments

Comments
 (0)