You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
638 B
16 lines
638 B
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
import { useCollector } from './useCollector';
|
|
export function useMonitorOutput(monitor, collect, onCollect) {
|
|
const [collected, updateCollected] = useCollector(monitor, collect, onCollect);
|
|
useIsomorphicLayoutEffect(function subscribeToMonitorStateChange() {
|
|
const handlerId = monitor.getHandlerId();
|
|
if (handlerId == null) {
|
|
return undefined;
|
|
}
|
|
return monitor.subscribeToStateChange(updateCollected, {
|
|
handlerIds: [handlerId],
|
|
});
|
|
}, [monitor, updateCollected]);
|
|
return collected;
|
|
}
|