Skip to content

useWindowFocus

Tracks whether the browser window currently has focus as a reactive Observable<boolean>. Updates automatically when the user switches tabs, clicks away, or returns to the window. SSR-safe: returns false when document is not available.

focused$.get() = false

Click outside this window or switch tabs to see the value change.

import { useWindowFocus } from "@usels/core";
function Component() {
const focused$ = useWindowFocus();
return <p>Window is {focused$.get() ? "focused" : "blurred"}</p>;
}
const focused$ = useWindowFocus();
useObserve(() => {
if (!focused$.get()) pausePolling();
else resumePolling();
});
export declare function useWindowFocus(): Observable<boolean>;

View on GitHub

  • tigerwest
  • a7392ab 2026-03-06 - feat(core,browser): add sync strategy hooks (tigerwest)