layoutItem is undefined `onDrop`
See original GitHub issueI have an onDrop function, which is nearly identical to the example:
function onDrop(layout, layoutItem, _event) {
console.log(layout, layoutItem, _event)
alert(`Dropped element props:\n${JSON.stringify(layoutItem, ['x', 'y', 'w', 'h'], 2)}`)
}
I have my draggable element:
<div className="toolbox-draggable-button"
draggable={true}
unselectable="on"
// this is a hack for firefox
// Firefox requires some kind of initialization
// which we can do by adding this attribute
// @see https://bugzilla.mozilla.org/show_bug.cgi?id=568313
onDragStart={e => e.dataTransfer.setData('text/plain', '')}>
Text here
</div>
Whenever onDrop is called, layoutItem is undefined, and I’d like to integrate this into my app so that when a user drags the element onto it, it actually makes an element drop in, but I can’t even get to that point if layoutItem returns undefined.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8
Top Results From Across the Web
Item is dropped in wrong position using react-grid-layout on ...
I figured out. I added data-grid={el} to the element which should be dropped. This is the code. import React from "react"; import _...
Read more >react-grid-layout/ReactGridLayout.jsx at master - GitHub
A draggable and resizable grid layout with responsive breakpoints, for React. - react-grid-layout/ReactGridLayout.jsx at master ...
Read more >ehome-react-grid-layout - npm
onDrop : (layout: Layout, item: ?LayoutItem, e: Event) => void, // Calls when an element is being dragged over the grid from outside...
Read more >LayoutItem Members | WPF Controls
Represents a control that consists of a label and content regions. The LayoutItem cannot be used outside a LayoutControl. #Constructors. Name, Description ...
Read more >react-grid-layout | Yarn - Package Manager
'start' and 'stop' callbacks pass `undefined` for 'placeholder'. // type ItemCallback = (layout: ... onDrop: (layout: Layout, item: ?LayoutItem, e: Event) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This seems to be the culprit - line below has a
layoutand afindfunction, but when it comes to ResponsiveGrid,layoutis not an array, its an object with defined breakpoints. https://github.com/react-grid-layout/react-grid-layout/blob/5126e7be9a1e38053e078f2b17e1a0f3a7abcda0/lib/ReactGridLayout.jsx#L753Interesting, so in order for the onDrop to work, I have to give up on saving the layout to LocalStorage, or otherwise. Good find!
I wish I could say I’d figured it out, but alas, not yet. Let me know if you find a fix.