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.
– Carlos Querioz
what I do there?
– Matheus Ribeiro
You connected the Redux to the component?
– Marconi
would that be the end of it? I put in question
– Matheus Ribeiro