@liveblocks/react-ui
Version:
A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.
23 lines (20 loc) • 576 B
JavaScript
import { useSyncExternalStore } from 'react';
function subscribe(callback) {
window.addEventListener("blur", callback);
window.addEventListener("focus", callback);
return () => {
window.removeEventListener("blur", callback);
window.removeEventListener("focus", callback);
};
}
function getSnapshot() {
return document.hasFocus();
}
function getServerSnapshot() {
return true;
}
function useWindowFocus() {
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
}
export { useWindowFocus };
//# sourceMappingURL=use-window-focus.js.map