useWindowsFocus
使用 window.onfocus
and window.onblur
事件跟踪页面焦点
Usage
实时编辑器
function Demo() { const focus = useWindowsFocus(); return ( <div> <p> {focus ? "💡 Click somewhere outside of the document to unfocus." : "ℹ Tab is unfocused"} </p> </div> ); };
结果
💡 Click somewhere outside of the document to unfocus.
API
useWindowsFocus
Returns
boolean
: 窗口是否聚焦
Arguments
参数名 | 描述 | 类型 | 默认值 |
---|---|---|---|
defauleValue | 默认值 | boolean | undefined | - |