mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
27 lines
523 B
TypeScript
27 lines
523 B
TypeScript
'use client'
|
|
|
|
import { startTransition, useReducer } from 'react'
|
|
|
|
function sleep(ms: number) {
|
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
}
|
|
|
|
export default function Page() {
|
|
const [counter, increment] = useReducer((n) => n + 1, 0)
|
|
|
|
function handleClick() {
|
|
startTransition(async () => {
|
|
await sleep(1000)
|
|
startTransition(() => {
|
|
increment()
|
|
})
|
|
})
|
|
}
|
|
return (
|
|
<>
|
|
<p>Count: {counter}</p>
|
|
<button onClick={handleClick}>Increment</button>
|
|
</>
|
|
)
|
|
}
|