fix: introduce action creators in redux-actions (#31170)

This commit is contained in:
Karthik Rao
2019-06-25 22:58:05 +05:30
committed by Randell Dawson
parent 274ef504c3
commit 782c5ba553

View File

@ -23,6 +23,25 @@ We can send these actions to the store by using
store.dispatch(action) store.dispatch(action)
``` ```
like so
```javascript
store.dispatch({
type: ADD_ITEM,
text: 'This is the first item'
})
```
In real world apps it is often better to use functions aptly called Action Creators that accept a payload and return the action object, making them reusable.
```javascript
function addItem(text) {
return {
type: ADD_ITEM,
text
}
}
store.dispatch(addItem('This is the second item'))
```
An application can have different sorts of events happening at a time and these actions help describe these events. Without these actions there is no way to change the state of the application. An application can have different sorts of events happening at a time and these actions help describe these events. Without these actions there is no way to change the state of the application.
## Action Creators ## Action Creators