无法读取未定义的属性“ closeModal1”

时间:2019-04-21 00:09:31

标签: reactjs react-redux

遇到此错误。尝试打开/关闭模式,并在状态打开或关闭后也对其进行更新。现在被卡住了一段时间,我似乎无法弄清楚。没有尝试过很多事情,因为我无法找到与我在Google上尝试做的事情或与stackoverflow相关的任何事情。我仍然是新手,如果代码使您感到恶心,请原谅我哈哈。预先感谢!

export const openModal1 = () => {
  return {
    type: "OPEN_MODAL"
  };
};
export const closeModal1 = () => {
  return {
    type: "CLOSE_MODAL"
  };
};



````````````````````````````````````````````````````````````````````````````
const INITIAL_STATE = {
  modalIsOpen: false
};

export default (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case "OPEN_MODAL":
      return { ...state, modalIsOpen: true };
    case "CLOSE_MODAL":
      return { ...state, modalIsOpen: false };
    default:
      return state;
  }
};

````````````````````````````````````````````````````````````````````````````
import { combineReducers } from "redux";
import authReducer from "./authReducer";
import modalReducer from "./modalReducer";

export default combineReducers({
  auth: authReducer,
  vis: modalReducer
});


1 个答案:

答案 0 :(得分:0)

openModal1和closeModal1函数应该在道具上。尝试将this.vis.openModal1()替换为this.props.openModal1()。