管理全局变量的状态以响应redux

时间:2019-12-06 03:45:48

标签: reactjs redux

如何获取此状态?我只需要在组件上将其设置为false和true即可,但是我做错了事,我知道在调用API时该怎么做,但不是这样。

我有以下操作:

import { HIDE_MENU, ESTADO_MENU } from "./types";

export const hideMenu = dispatch => {
  return dispatch({
    type: HIDE_MENU
  });
};

export const estadoDoMenu = open => dispatch => {
  dispatch({
    type: ESTADO_MENU
  });
};

和这个减速器:

import { HIDE_MENU, ESTADO_MENU } from "../actions/types";

const initialState = {
  open: true
};

export default function(state = initialState, action) {
  switch (action.type) {
    case HIDE_MENU:
      return {
        ...state,
        open: false
      };
    case ESTADO_MENU:
      console.log("chega aqui");
      return {
        ...state
      };
    default:
      return state;
  }
}

但这样称呼它:

componentDidMount() {
    console.log("Estado do Menu: ", this.props.estadoDoMenu());
  }

我在控制台上收到undefined,怎么了?

0 个答案:

没有答案