跳到主要内容

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>
  );
};

结果
Loading...

API

useWindowsFocus

Returns

boolean: 窗口是否聚焦

Arguments

参数名描述类型默认值
defauleValue默认值boolean | undefined-