react-upload-gallery icon indicating copy to clipboard operation
react-upload-gallery copied to clipboard

A state mutation was detected between dispatches but I haven't mutated state

Open waqasxh opened this issue 2 years ago • 3 comments

I my functional component I am setting InitialState via state variable that is fetched from API call and passed in from Redux, I am getting "A state mutation was detected between dispatches but I haven't mutated state" error.

waqasxh avatar Apr 23 '22 07:04 waqasxh

Can you send a sample project from here? https://codesandbox.io/

m-inan avatar Apr 29 '22 20:04 m-inan

I found and fixed the issue, in RUG.js constructor, initialState.reverse() is being called that is trying to mutate the state

this.state = { images: initialState .reverse() .map((item) => { return this.create({ done: true, ...item, }); }) .reverse(),

  renderComponent: !ssrSupport,
};

waqasxh avatar Apr 29 '22 21:04 waqasxh

@m-inan It seem quite unintuitive to reverse the array like that. I'm not sure what you were trying to achieve, but array.map already returns a new array, in case you were trying to keep it pure. As a result, when adding a photo, it's appended as if the layout is RTL. It's expected to have photos append from LTR by default. @waqasxh Did you try setting the inOrder prop to true?

adi-doorloop avatar Jun 25 '24 13:06 adi-doorloop