useWindowsFocus

React Element Hook that tracks window focus with window.onfocus and window.onblur events.

Usage

import { useWindowsFocus } from "@reactuses/core";

const Demo = () => {
  const focus = useWindowsFocus();
  return (
    <div>
      <p>
        {focus
          ? "💡 Click somewhere outside of the document to unfocus."
          : "ℹ Tab is unfocused"}
      </p>
    </div>
  );
};

Example

ℹ Tab is unfocused

Type Declarations

export default function useWindowsFocus(): boolean