useWindowEvent
useWindowEventは、windowへ指定されたイベントリスナーを割り当てるカスタムフックです。
Click count: 0
const [count, setCount] = useState(0)
useWindowEvent("click", () => {
setCount((prev) => prev + 1)
})
return <Text>Click count: {count}</Text>
こちらのコードを使用する場合は、
"use client"をファイルの上部に追加する必要があります。使い方
import { useWindowEvent } from "@yamada-ui/react"
import { useWindowEvent } from "@/components/ui"
import { useWindowEvent } from "@workspaces/ui"
const [count, setCount] = useState(0)
useWindowEvent("click", () => {
setCount((prev) => prev + 1)
})