import * as React from 'react'
import { FormWithArg, Form, ErrorBoundary } from './client'
const action = async (...args: any[]) => {
'use server'
console.log('hello from server', ...args)
return 'state-from-server'
}
// simulate client-side version skew by changing the action ID to something the server won't recognize
setServerActionId(action, 'decafc0ffeebad01')
export default function Page() {
return (
Submit client form with simple argument
Submit client form with complex argument
)
}
function setServerActionId(action: (...args: any[]) => any, id: string) {
// React implementation detail: `registerServerReference(func, id)` sets `func.$$id = id`.
const actionWithMetadata = action as typeof action & { $$id?: string }
if (!actionWithMetadata.$$id) {
throw new Error(
`Expected to find server action metadata properties on ${action}`
)
}
Object.defineProperty(actionWithMetadata, '$$id', {
value: id,
configurable: true,
})
}