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