Skip to content

Commit ae90941

Browse files
committed
Add support for createAction as type
1 parent d1aa7d6 commit ae90941

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ expect(increment(error)).to.deep.equal({
4747
});
4848
```
4949

50+
`createAction` also returns its `type` when used as type in `handleAction` or `handleActions`.
51+
52+
Example:
53+
54+
```js
55+
const increment = createAction('INCREMENT');
56+
57+
// As parameter in handleAction:
58+
handleAction(increment, {
59+
next(state, action) {...}
60+
throw(state, action) {...}
61+
});
62+
63+
// As object key in handleActions:
64+
const reducer = handleActions({
65+
[increment]: (state, action) => ({
66+
counter: state.counter + action.payload
67+
})
68+
}, { counter: 0 });
69+
```
70+
5071
**NOTE:** The more correct name for this function is probably `createActionCreator()`, but that seems a bit redundant.
5172

5273
Use the identity form to create one-off actions:

0 commit comments

Comments
 (0)