Files
coopgo/node_modules/react-dnd/lib/core/DragPreviewImage.js
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

24 lines
584 B
JavaScript

import { useEffect, memo } from 'react';
/**
* A utility for rendering a drag preview image
*/
export const DragPreviewImage = memo(function DragPreviewImage({ connect, src }) {
useEffect(() => {
if (typeof Image === 'undefined')
return;
let connected = false;
const img = new Image();
img.src = src;
img.onload = () => {
connect(img);
connected = true;
};
return () => {
if (connected) {
connect(null);
}
};
});
return null;
});