Javascript 从withHandlers中的withReducer检索重新组合本地分派函数

Javascript 从withHandlers中的withReducer检索重新组合本地分派函数,javascript,reactjs,recompose,Javascript,Reactjs,Recompose,我有一个组件,它已经连接到redux存储,并向其注入了dispatch。我正在尝试使用withReducer和withHandlers更新组件的本地状态,如下所示: const reducer = (state, action) => { switch (action.type) { case 'SET_ACTIVE_TAB': console.log('recieved action', action) const { activeTab } = ac

我有一个组件,它已经连接到
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
  }
}

我发现当我撰写时:

compose(handlers, enhancer)(LayerListItem)

dispatchLocal
属性未在
处理程序中定义。使用
recompose
创建和绑定动作创建者以更新应用程序状态的最佳方法是什么。

您应该将
withReducer
移动到
withHandlers
的右侧:

compose(
  withReducer(...),
  withHandlers(...)
)

这样,
withReducer
将首先创建分派函数并将其附加到
props
,然后
withHandlers
可以使用它。

您应该将
withReducer
移动到
withHandlers
的右侧:

compose(
  withReducer(...),
  withHandlers(...)
)
这样,
withReducer
将首先创建分派函数并将其附加到
props
,然后
withHandlers
可以使用它