2

There is such local function (in functional component with state provided useState hook) that has a deal with the state

      let setContainer = container => {
        let newState = {...state, files: deleteAllFromTo(state.files), container}
        let newStateIntermediate = JSON.parse(JSON.stringify(newState))
    
        console.log('-----------------')
        console.log(newState)
        console.log(newStateIntermediate)
        setState(newStateIntermediate)
      }

Why the newState and newStateIntermediate are able to be different?

enter image description here

misterx527
  • 97
  • 5
  • 1
    Does this answer your question? [Is Chrome's JavaScript console lazy about evaluating arrays?](https://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays) – ASDFGerte Jul 19 '20 at 15:53

2 Answers2

0

Don't rely on console.log to test deep equality. As ASDFGerte and this question have pointed, it might be lazy. Use, for instance, lodash.isEqual for that. If it happens to return false, then inspect the objects.

Rodrigo Amaral
  • 1,324
  • 1
  • 13
  • 17
0

Thank you everyone for your sugestions. The problem was that in the first case 'to' is a property of the audio object, but in the second one 'to' is a property of audio[0].

misterx527
  • 97
  • 5