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
可以使用它