react-dnd
Version:
Drag and Drop for React
16 lines (15 loc) • 596 B
JavaScript
import { useLayoutEffect } from 'react';
import { useCollector } from './useCollector';
export function useMonitorOutput(monitor, collect, onCollect) {
const [collected, updateCollected] = useCollector(monitor, collect, onCollect);
useLayoutEffect(function subscribeToMonitorStateChange() {
const handlerId = monitor.getHandlerId();
if (handlerId == null) {
return undefined;
}
return monitor.subscribeToStateChange(updateCollected, {
handlerIds: [handlerId],
});
}, [monitor, updateCollected]);
return collected;
}