Answer the question
In order to leave comments, you need to log in
Why is the reducer not working in Redux?
Greetings) Why does the reducer in Redux not work? I would be grateful for any help.
openModal.js ( action )
export const OPEN_MODAL = "OPEN_MODAL";
const openModal = isOpen => {
console.log(isOpen); /*Тут консоль срабатывает, выводит true */
return {
type: OPEN_MODAL,
payload: {
isOpen: isOpen
}
};
};
export default openModal;
import { OPEN_MODAL } from "../../actions/Modal/openModal";
const initialState = {
isOpen: false
};
const modalR = (state = initialState, action) => {
switch (action.type) {
case OPEN_MODAL:
console.log(action); /*Тут консоль НЕ срабатывает */
return {
...state,
isOpen: action.payload.isOpen
};
default:
return state;
}
};
export default modalR;
import { combineReducers } from "redux";
import modalR from "./Modal/modalR";
export const rootReducer = combineReducers({
modal: modalR
});
Answer the question
In order to leave comments, you need to log in
does it even reach the reducer?
import { OPEN_MODAL } from "../../actions/Modal/openModal";
const initialState = {
isOpen: false
};
const modalR = (state = initialState, action) => {
// а тут консоль?
console.log(action) // ?
switch (action.type) {
case OPEN_MODAL:
console.log(action); /*Тут консоль НЕ срабатывает */
return {
...state,
isOpen: action.payload.isOpen
};
default:
return state;
}
};
export default modalR;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question