How to manage the state of a variable without calling the API

Asked

Viewed 35 times

1

With the reducer:

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:
            return {
                ...state
            }
        default:
            return state;
    }
}

and the action:

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

export const hideMenu = () => dispatch => {
    dispatch({
        type: HIDE_MENU,
        data: false
    })
}

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

When I call in the component:

componentDidMount() {
    this.props.fetchTotalUsuariosBloqueados();
    this.props.fetchTotalSolicitacao();

    console.log("Estado do Menu: " + this.props.estadoDoMenu());
    if (this.props.estadoDoMenu() == true) this.setState({ open: false });
  }

export default connect(mapStateToProps, {
  fetchTotalUsuariosBloqueados,
  fetchTotalSolicitacao,
  estadoDoMenu,
  hideMenu
})(onClickOutside(Menu));

He’s like undefined, what I’m doing wrong?

  • Matheus, it would be good if you put the chunk of the component where you call this function. You passed it by mapDispatchToProps? Another detail is that its function has no return, so the return is Undefined (void) same.

  • what I do there?

  • You connected the Redux to the component?

  • would that be the end of it? I put in question

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.