Q
Q
qfrontend2020-08-24 18:52:13
React
qfrontend, 2020-08-24 18:52:13

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;


modalR.js ( reducer )
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;


rootReducer.js
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

2 answer(s)
H
hzzzzl, 2020-08-24
@hzzzzl

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;

D
Dmitry Kulakov, 2020-09-02
@Sqvall

Check if you dispatch the action when it is called?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question