Reactjs 动作成功分派,有效负载到达减速器,但状态保持不变。反应+;重演

Reactjs 动作成功分派,有效负载到达减速器,但状态保持不变。反应+;重演,reactjs,redux,react-redux,Reactjs,Redux,React Redux,我执行了一项操作,将当前页面设置为表中的分页。动作被成功调度,正确的负载到达了redux开发工具中看到的减速器,但状态没有改变。我不知道为什么会这样。我所有的行动都很好,但这次我面临这个问题。 这是我的行动-> import { SET_CURRENT_PAGE } from "./types"; export const setCurrentPage = page => { return { type: SET_CURRENT_PAGE, page }; };

我执行了一项操作,将当前页面设置为表中的分页。动作被成功调度,正确的负载到达了redux开发工具中看到的减速器,但状态没有改变。我不知道为什么会这样。我所有的行动都很好,但这次我面临这个问题。 这是我的行动->

import { SET_CURRENT_PAGE } from "./types";

export const setCurrentPage = page => {
  return {
    type: SET_CURRENT_PAGE,
    page
  };
};

这是我的减速机

import { SET_CURRENT_PAGE } from "../actions/types";

const initialState = {
  currentPage: 1
};

export default (state = initialState, action) => {
  switch (action.payload) {
    case SET_CURRENT_PAGE: {
      return {
           ...state,
           currentPage:action.page
       };
    }
    default:
      return state;
  }
};

我在我的表组件中调用此操作。从那里成功地调度了操作。我不知道为什么状态没有更新。

如果代码中有一个小错误,请将switch语句中的
操作有效负载
更改为
操作。键入

试试这个

import { SET_CURRENT_PAGE } from "../actions/types";
const initialState = {
  currentPage: 1
};
export default (state = initialState, action) => {
  switch (action.type) {
    case SET_CURRENT_PAGE: {
      return {
           ...state,
           currentPage:action.page
       };
    }
    default:
      return state;
  }
};

如果代码中有一个小错误,请将
action.payload
更改为
action.type

试试这个

import { SET_CURRENT_PAGE } from "../actions/types";
const initialState = {
  currentPage: 1
};
export default (state = initialState, action) => {
  switch (action.type) {
    case SET_CURRENT_PAGE: {
      return {
           ...state,
           currentPage:action.page
       };
    }
    default:
      return state;
  }
};

尝试在您的操作中添加有效负载,如下所示

import { SET_CURRENT_PAGE } from "./types";

export const setCurrentPage = page => {
  return {
    type: SET_CURRENT_PAGE,
    payload: page
  };
};
使用开关箱类型和有效载荷设置状态,如

import { SET_CURRENT_PAGE } from "../actions/types";
const initialState = {
  currentPage: 1
};
export default (state = initialState, action) => {
  switch (action.type) {
    case SET_CURRENT_PAGE: {
      return {
           ...state,
           currentPage:action.payload
       };
    }
    default:
      return state;
  }
};

尝试在您的操作中添加有效负载,如下所示

import { SET_CURRENT_PAGE } from "./types";

export const setCurrentPage = page => {
  return {
    type: SET_CURRENT_PAGE,
    payload: page
  };
};
使用开关箱类型和有效载荷设置状态,如

import { SET_CURRENT_PAGE } from "../actions/types";
const initialState = {
  currentPage: 1
};
export default (state = initialState, action) => {
  switch (action.type) {
    case SET_CURRENT_PAGE: {
      return {
           ...state,
           currentPage:action.payload
       };
    }
    default:
      return state;
  }
};