--- title: useWindowEvent description: "`useWindowEvent`は、`window`へ指定されたイベントリスナーを割り当てるカスタムフックです。" links: - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/hooks/use-window-event - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/hooks-usewindowevent--basic --- ```tsx const [count, setCount] = useState(0) useWindowEvent("click", () => { setCount((prev) => prev + 1) }) return Click count: {count} ``` ## 使い方 ```tsx import { useWindowEvent } from "@yamada-ui/react" ``` ```tsx import { useWindowEvent } from "@/components/ui" ``` ```tsx import { useWindowEvent } from "@workspaces/ui" ``` ```tsx const [count, setCount] = useState(0) useWindowEvent("click", () => { setCount((prev) => prev + 1) }) ```