Coder Social home page Coder Social logo

Comments (3)

Jonathan-Hofmann avatar Jonathan-Hofmann commented on June 12, 2024 5

I have the same error in my project.

EDITED:
I have found a workaround for my case.

I previously have used the onLayoutChange callback for saving the grid layout. But as onLayoutChange is now called multiple times (in my case 3 times!! per move) it resets the previously made changes back to the original.
(So basically saves 3 times. 1st = new changes; 2nd & 3rd = previous layout -> Overwrites old 'saved' changes).
As a result one could not even move a widget anymore as the layout was being reset all the time.

The workaround I found is to use the onDragStop callback to save the newest layout/widget position. This works great and is only being called ONCE and not twice/three times when a widget is moved.

In addition as I needed to save the new position (of the widget) in the currently visible breakpoint I also needed to add the onBreakointChange callback to always receive the current visible breakpoint to save in.

One note for the onBreakointChange callback: This callback seems to NOT be called initially when first rendered so I had to create a useEffect Hook to calculate the initial breakpoint on initial render.

I hope this helps a bit / with this you can work on fixing your code :)

from react-grid-layout.

davidliudev avatar davidliudev commented on June 12, 2024

@Jonathan-Hofmann Thanks man for saving my day. Having the exact same issue and the layout got overwritten and it is a mess. Your workaround works great!

The onLayoutChange callback definitely need some re-work to avoid duplicated calling..

from react-grid-layout.

rever96 avatar rever96 commented on June 12, 2024

yeah, your tips helped me too.

// onLayoutChange={handleLayoutChange} // called too many times
onDragStop={handleLayoutChange}
onResizeStop={handleLayoutChange}

but I still have problems on y position when having elements of different height in grid

from react-grid-layout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.