javascript - 未捕获的类型错误 : Cannot read property 'type' of undefined React/Redux

原文 标签 javascript reactjs redux render-to-string

我只是在学习 redux/reactjs。我正在尝试使用 redux 进行服务器端渲染但不幸的是我收到了这个错误。是的,那里有很多答案,但对我不起作用。
enter image description here

headerReducer.js

import * as type from '../Actions/actionTypes';


const initialState = {
    menuToggle:false,
    singnInToggle:false,
    removeUploadMenu:true,
    uploadPopUp:false
};
export default function toogleReducer(state=initialState,action) {
  switch (action.type){
      case type.NAVBAR_TOGGLE:
          return(
              Object.assign({},state,{menuToggle:action.payload})
          );
      case type.SIGNINPOP_TOGGLE:
          return(
              Object.assign({},state,{singnInToggle:action.payload})
          );
      case type.REMOVEUPLOADMENU:
          return(
              Object.assign({},state,{removeUploadMenu:action.payload})
          );
      case type.TOGGLEUPLOADPOPUP:
          return(
              Object.assign({},state,{uploadPopUp:action.payload})
          );
      case type.TOGGLEUPLOADPOPUPOFF:
          return(
              Object.assign({},state,{uploadPopUp:action.payload})
          )
      default:
          return state
  }
}

headerActions.js
import * as types from './actionTypes';

export function toggleStatus(bool) {
    return{
        type:types.NAVBAR_TOGGLE,
        payload:bool
    }
}
export function toggleSignPop(bool) {
    return{
        type:types.SIGNINPOP_TOGGLE,
        payload:bool
    }
}

export function removeUploadMenu(bool) {
    return{
        type:types.REMOVEUPLOADMENU,
        payload:bool
    }
}

export function toggleUploadPopun(bool) {
    return{
        type:types.TOGGLEUPLOADPOPUP,
        payload:bool
    }
}

reducer /index.js
import {combineReducers} from 'redux';
import toggleReducer from './headerReducer';
import loginStatusReducer from './AuthReducer';
import photoUploadReducer from './photoUploadingReducer';
import notificationReducer from './NotificationReducer';
import supportForUploadReducer from './supportForUploadReducer';

export default combineReducers({
  toggle:toggleReducer,
    logInStatus:loginStatusReducer,
  photoUpload:photoUploadReducer,
  notification:notificationReducer,
  loadedAjax:supportForUploadReducer
});

最佳答案

我怀疑您的组件没有正确连接到 Redux 商店。看this Dan Abramov's example .你应该特别拥有 dispatch将您的操作连接到 Redux 存储时使用。例子:

const mapDispatchToProps = (dispatch) => {
  return {
    onTodoClick: (id) => {
      dispatch(toggleTodo(id));
    },
  };
};

关于javascript - 未捕获的类型错误 : Cannot read property 'type' of undefined React/Redux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41072301/

相关文章:

javascript - 尝试在react中添加多个图像,但仅显示一个图像

javascript - 如何将UIWebViewNavigationTypeLinkClicked伪造为UIWebVIew

javascript - Q Promise 链接,未调用错误处理程序

reactjs - 如何使用 Material 表 react 仅在编辑或创建模式下显示隐藏列?

reactjs - 在React中,如何处理来自服务器的错误?

javascript - 在 Redux mapDispatchToProps 中使用组件状态或 Prop

javascript - Google Maps API 反向查找地址详细信息准确性

javascript - 使用Angular指令中的jQuery.matchHeight

javascript - 用于配置的对象生成器

javascript - 如何在reactjs中使用响应ajax请求设置状态