useWindowsFocus
React Element Hook that tracks window focus with window.onfocus and window.onblur events
Usage
Live Editor
function Demo() { const focus = useWindowsFocus(); return ( <div> <p> {focus ? "💡 Click somewhere outside of the document to unfocus." : "ℹ Tab is unfocused"} </p> </div> ); };
Result
💡 Click somewhere outside of the document to unfocus.
API
useWindowsFocus
Returns
boolean: whether window focus
Arguments
| Argument | Description | Type | DefaultValue |
|---|---|---|---|
| defauleValue | defauleValue | boolean | undefined | - |