mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Implements https://x.com/sebmarkbage/status/1842240773867126939 supersedes and closes #66054 (with permission)
24 lines
451 B
TypeScript
24 lines
451 B
TypeScript
'use client'
|
|
|
|
import { useActionState } from 'react'
|
|
|
|
export function Form({
|
|
action,
|
|
}: {
|
|
action: (obj: object | null) => Promise<object | null>
|
|
}) {
|
|
const [result, formAction] = useActionState(async () => {
|
|
const objA = {}
|
|
const objB = await action(objA)
|
|
|
|
return objA === objB ? 'identical' : 'kaputt!'
|
|
}, 'initial')
|
|
|
|
return (
|
|
<form action={formAction}>
|
|
<button>Submit</button>
|
|
<p>{result}</p>
|
|
</form>
|
|
)
|
|
}
|