useTimeout
useTimeout
is a custom hook that executes a function after a specified number of milliseconds.
Current state: 1
const [state, setState] = useState<number>(1)
useTimeout(() => setState((prev) => prev + 1), 3000)
return <Text>Current state: {state}</Text>
If you use this code, you need to add
"use client"
to the top of the file.Usage
import { useTimeout } from "@yamada-ui/react"
import { useTimeout } from "@/components/ui"
import { useTimeout } from "@workspaces/ui"
const [state, setState] = useState<number>(1)
useTimeout(() => setState((prev) => prev + 1), 3000)