m-inan / react-upload-gallery

React for Upload Image Gallery. Sorted by drag & drop and Customizable
MIT License
80 stars 44 forks source link

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

Open waqasxh opened 2 years ago

waqasxh commented 2 years ago

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.

m-inan commented 2 years ago

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

waqasxh commented 2 years ago

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,
};
adi-doorloop commented 4 months ago

@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?