Skip to main content

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
Loading...

API

useWindowsFocus

Returns

boolean: whether window focus

Arguments

ArgumentDescriptionTypeDefaultValue
defauleValuedefauleValueboolean | undefined-