2017-09-26 46 views
1

我正在使用路由器组件来路由我的应用程序。我有这样一个文件:store.dispatch不是函数

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不是一个函数。我错过了什么?为什么这条消息出现?是不是存储全局变量?

回答

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)