sleep

sleep is a utility to delay execution for a specific duration.

Import#

import { sleep } from '@dwarvesf/react-utils'

Return value#

This method returns a promise that will resolve after X ms has passed.

Usage#

function Example() {
const [state, setState] = useState(
"Click me and I'll change after 5 seconds!!",
)
const onClick = async () => {
await sleep(5000)
setState('Tada!')
}
return (
<Stack>
<Button onClick={onClick}>{state}</Button>
</Stack>
)
}

Parameters#

The sleep method accepts a time parameter in miliseconds:

sleep(time)
NameTypeDefaultDescription
timenumber_The time to wait for before continue execution.
Edit this page

Made with ❤️ by Dwarves Foundation