2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Map Dispatch to Props
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Map Dispatch to Props
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
2019-05-09 06:27:06 -07:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2019-05-09 06:27:06 -07:00
|
|
|
```jsx
|
|
|
|
const addMessage = (message) => {
|
|
|
|
return {
|
|
|
|
type: 'ADD',
|
|
|
|
message: message
|
|
|
|
}
|
|
|
|
};
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-05-09 06:27:06 -07:00
|
|
|
// change code below this line
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
return {
|
|
|
|
submitNewMessage: (message)=>{
|
|
|
|
dispatch(addMessage(message))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
</details>
|