[英]store.dispatch is not a function
I'm using a router component for routing my app. 我正在使用路由器组件来路由我的应用程序。 I have a file like this:
我有一个像这样的文件:
import CustomerDetailsContainer from '../views/CustomerDetails/customerDetailsContainer';
import CustomerInfoContainer from '../views/CustomerInfo/customerInfoContainer';
import { setUIState } from '../../actions/index';
const inCustomerInfo = (store) => {
store.dispatch(setUIState(CURRENT_SCREEN, 'customerInfo'));
};
const inCustomerDetails = (store) => {
store.dispatch(setUIState(CURRENT_SCREEN, 'customerDetails'));
};
export default (store) => {
return [
authenticatedRouteConfig(
store,
`/${CUSTOMER_INFO}`,
CustomerInfoContainer,
inCustomerInfo
),
authenticatedRouteConfig(
store,
`/${CUSTOMER_DETAILS}/:cid`,
CustomerDetailsContainer,
inCustomerDetails
),
];
};
And error is showing that store.dispatch
is not a function. 错误显示
store.dispatch
不是函数。 What am i missing? 我想念什么? Why this message is appearing?
为什么会出现此消息? Isn't store a global variable?
不存储全局变量吗?
You have to use dispatch from redux to dispatch action. 您必须使用来自redux的dispatch来执行dispatch操作。
import {connect} from "react-redux"
const mapDispatchToProps = (dispatch) => {
return {
inCustomerInfo : (setUIState) => {
dispatch(setUIState(CURRENT_SCREEN, 'customerInfo')
},
inCustomerDetails : (setUIState) => {
dispatch(setUIState(CURRENT_SCREEN, 'customerDetails')
}
}
export default connect(mapDispatchToProps)(Comp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.