react-grid-dnd icon indicating copy to clipboard operation
react-grid-dnd copied to clipboard

Fix for images

Open a-drewsky opened this issue 3 years ago • 4 comments

I don't know if this has been addressed but it took me an hour to figure out. If you want to use images in the grid items you have to add onDragStart={(e) => {e.preventDefault()}} to the img element.

a-drewsky avatar Jun 10 '21 01:06 a-drewsky

This was a bit laggy at first, but then started working beautifully, thank you!

fomson avatar Jul 09 '21 03:07 fomson

@a-drewsky do you have problem with the order after dragging?

function onChange(sourceId, sourceIndex, targetIndex, targetId) {
		const nextState = swap(items, sourceIndex, targetIndex)
		setItems(nextState)
	        console.log('items', items)
	}

in this code I tried to see the state in console after dragging. The console will show the previous state now the after dragging. Any idea why ?

applemate avatar Sep 08 '21 20:09 applemate

Thanks!

mleister97 avatar Jun 29 '22 11:06 mleister97

@a-drewsky do you have problem with the order after dragging?

function onChange(sourceId, sourceIndex, targetIndex, targetId) {
		const nextState = swap(items, sourceIndex, targetIndex)
		setItems(nextState)
	        console.log('items', items)
	}

in this code I tried to see the state in console after dragging. The console will show the previous state now the after dragging. Any idea why ?

(I realize this comment is a bit old, but figured I'd answer anyways.) This is simply how React works. After calling your setter function from the useState hook, the new value of your state will not be reflected in the state variable until the next iteration of the event loop. This makes it so that each iteration of the loop has a consistent snapshot of the state of your application.

BigBahss avatar May 15 '23 21:05 BigBahss