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