【发布时间】:2017-08-15 07:39:57
【问题描述】:
我有一个组件已经连接到 redux 存储,并且已经注入了 dispatch。我正在尝试使用withReducer 和withHandlers 更新组件的本地状态,如下所示:
const reducer = (state, action) => {
switch (action.type) {
case 'SET_ACTIVE_TAB':
console.log('recieved action', action)
const { activeTab } = action
return activeTab
default:
return state
}
}
const initialState = 'actions'
const handlers = withHandlers({
onTabClick: props => (e, { name }) => {
const { dispatchLocal } = props
dispatchLocal({
type: 'SET_ACTIVE_TAB',
activeTab: name
})
}
})
const enhancer = withReducer('activeTab', 'dispatchLocal', reducer, initialState)
我发现当我compose:
compose(handlers, enhancer)(LayerListItem)
dispatchLocal 属性未在 handler 中定义。使用recompose 创建和绑定动作创建者以更新应用程序状态的最佳方法是什么。
【问题讨论】:
标签: javascript reactjs recompose