store.dispatch不是一个函数

时间:2017-09-26 15:05:28

标签: javascript reactjs react-router

我使用路由器组件来路由我的应用。我有这样一个文件:

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
    ),
  ];
};

错误显示store.dispatch不是函数。我错过了什么?为什么会出现此消息?不存储全局变量吗?

1 个答案:

答案 0 :(得分:2)

您必须使用redux的调度来发送行动。

 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)