Skip to content

pre state is wrong with object state #13

@SilvaQ

Description

@SilvaQ

if the state is object ,logger pre state will be change ,so pre and now is the same ref.

we need to deep copy befor excute the reducer.

my code:

 (state, action) => {
      const preState = { ...state };  //  deep copy first befor consume
      const next = reducer(state, action);
      if (debug) {
        console.group(
          `%cAction【${action.type}】%cat ${getCurrentTimeFormatted()}`,
          "color: lightgreen; font-weight: bold;",
          "color: #9E9E9E; font-weight: 700;",
          "color: lightblue; font-weight: lighter;"
        );
        // 上一个state
        console.log(
          "%cPrevious State:",
          "color: #9E9E9E; font-weight: 700;",
          preState
        );

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions