Redux 状态 - 只是有时它显示“状态是平等的”

问题描述

我正在将 ReactJS 与 Redux 一起使用,但在 Redux 更新时遇到问题。

在一个组件中,我有以下内容:

import { connect } from "react-redux";
import { Dispatch } from "redux";
import { State } from "state/State";
import { FormActions } from "state/form/actions";
import { StateToProps,DispatchToProps,DialogMetaComponent } from "./types";
import hasResponseId from "utils/hasResponseId";
import PrintDialog,{ COMMAND_RESPONSE_ID } from "./PrintDialog";

const mapDispatchToProps = (
  dispatch: Dispatch,{ metaComponent }: { metaComponent: DialogMetaComponent },): DispatchToProps => ({
  onCleanUpCancel: () => {
    const { cancelCommands }: DialogMetaComponent = metaComponent;

    if (
      !cancelCommands ||
      (Array.isArray(cancelCommands) && !cancelCommands.length)
    ) {
      return;
    }

    cancelCommands.map((command) =>
      dispatch(
        FormActions.removeCommand({
          id: command,}),),);
  },});

export default connect(mapStateToProps,mapDispatchToProps)(PrintDialog);

动作:

export interface FormCommand {
  id: string;
  forResponseId?: string;
  params?: {
    [key: string]: any;
  };
  [key: string]: any;
}

export const FormActions = {
  removeCommand: (command: FormCommand) =>
    action(FormActionTypes.REMOVE_COMMAND,command),}

这是对应的reducer:

case FormActionTypes.REMOVE_COMMAND:
  {
    const commands = state.commands.filter(
      (command: FormCommand) =>
      !command.forResponseId ||
      !command.forResponseId.includes(action.payload.id),);

    return {
      ...state,commands: [...commands],};
  }

大多数时候它会正确删除命令。 但有时 redux 会说:状态是平等的。并且不会删除任何命令。

通常我希望:

FormActions.removeCommand({
  id: command,})

总是创建一个新对象(带有新的引用)。

你有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)