我有一个已连接到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创建和绑定动作创建者以更新应用程序状态的最佳方式是什么。