Reactjs 从返回函数内的onChange事件分派时出错
以下是onChange事件:Reactjs 从返回函数内的onChange事件分派时出错,reactjs,redux,react-redux,Reactjs,Redux,React Redux,以下是onChange事件: onChange={(event, newValue) => { this.props.changeTabState(newValue) }} 这是发送给道具的消息: const mapDispatchToProps = (dispatch) => ({ changeTabState: (newTabState) => dispatch(changeTabState(newTabState)) }) 在我调用this.pr
onChange={(event, newValue) => {
this.props.changeTabState(newValue)
}}
这是发送给道具的消息:
const mapDispatchToProps = (dispatch) => ({
changeTabState: (newTabState) => dispatch(changeTabState(newTabState))
})
在我调用this.prop.changeTabState的行中,出现了一个名为“TypeError:redux\u actions\u tab\u action\u WEBPACK\u IMPORTED\u MODULE\u 12\u不是函数”的错误
以下是初始状态:
export const TAB_STATE = () => {
return{
tab: 0
}
}
export const TAB_CHANGE = "tab_action"
选项卡操作文件:
import {TAB_CHANGE} from '../utils'
export const changeTabState = (newTabState) => {
return {
type : TAB_CHANGE,
payload : newTabState
}
}
选项卡文件:
import { TAB_STATE, TAB_CHANGE } from '../utils'
import _ from 'lodash'
export const tabReducer = (state = TAB_STATE(), action) => {
switch (action.type) {
case TAB_CHANGE: {
let newState = _.cloneDeep(state)
newState = { ...newState, ...action.payload }
return newState
}
}
return state
}
好的,我通过改变导入方式解决了这个问题 之前我是这样导入的:
import * as changeTabState from '../../redux/actions/tab_action'
import {changeTabState} from '../../redux/actions/tab_action'
onChange={(event, newTabState) => {
this.props.changeTabState({tab: newTabState})
})
}}
但现在我像这样导入:
import * as changeTabState from '../../redux/actions/tab_action'
import {changeTabState} from '../../redux/actions/tab_action'
onChange={(event, newTabState) => {
this.props.changeTabState({tab: newTabState})
})
}}
我还更改了在onChange中发送的状态,如下所示:
import * as changeTabState from '../../redux/actions/tab_action'
import {changeTabState} from '../../redux/actions/tab_action'
onChange={(event, newTabState) => {
this.props.changeTabState({tab: newTabState})
})
}}
请添加更多的代码以导出您使用createStore的类和文件,以获得更多说明。好的,我马上添加。添加了其他代码。