Skip to main content

useWindowFocus

Hook to track the focus state of the window.

Usage

Live Editor
function App() {
	const isWindowFocused = useWindowFocus();

	return (
		<div>
			<h1>Window Focus Hook</h1>
			<p>{isWindowFocused ? "Window is focused" : "Window is not focused"}</p>
		</div>
	);
}
Result
Loading...

API

Returns : A boolean value indicating whether the window is focused or not, updated in real-time. Useful for tracking the if the user is currently interacting with the window.