最近几天,我学会了重新组合,正在做CRUD
Message.js
const Message = ({mssg}) => {
return (
<div>
<p>
{mssg}
</p>
</div>
)
}
const mapStateToProps = (state) => ({mssg: state.message})
export default compose(
connect(
mapStateToProps
)
)(Message)
AddTask.js
const mapDispatchToProps = (dispatch) => ({
onAdd: task => {
dispatch(actions.add(task))
},
changeMssg: mssg => {
dispatch(actions.changeMessage(mssg))
}
})
export default compose(
connect(
null,
mapDispatchToProps
),
withStateHandlers(
{
task: ''
},
{
handleOnChange: () => event => {
let mergeState = {
[event.target.id]: event.target.value
}
return mergeState
},
handleOnAdd: (state, {onAdd, changeMssg}) => {
onAdd(state)
changeMssg(messages.MSSG_ADD)
}
}
)
)(AddTask)
在AddTask组件中,添加任务后,消息将被更改。但是我遇到了错误
Recompose.esm.js:385 Uncaught TypeError: Cannot read property 'apply' of undefined
at WithStateHandlers.<anonymous> (Recompose.esm.js:385)
有人能解释一下为什么吗,请帮帮我吗?