META-INF.resources.js.hooks.useDragSource.ts Maven / Gradle / Ivy
The newest version!
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import {useEffect} from 'react';
import {useDrag} from 'react-dnd';
import {getEmptyImage} from 'react-dnd-html5-backend';
type Item = {
type: string;
[key: string]: any;
};
export default function useDragSource({item}: {item: Item}) {
const [{isDragging}, handlerRef, previewRef] = useDrag({
collect: (monitor) => ({
isDragging: monitor.isDragging(),
}),
item,
});
useEffect(() => {
previewRef(getEmptyImage(), {captureDraggingState: true});
}, [previewRef]);
return {handlerRef, isDragging};
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy