'use client' import * as React from 'react' import { useActionState } from 'react' export function FormWithArg({ action, argument, id, children, }: { action: (state: string, argument: T) => Promise argument: T id: string children?: React.ReactNode }) { const [state, dispatch] = useActionState( // don't use `bind()`, we want to explicitly avoid getting a FormData argument // because that always results in a FormData request (state) => action(state, argument), 'initial-state' ) return (
{`${state}`}
) } export function Form({ action, }: { action: (state: string, formData: FormData) => Promise }) { const [state, dispatch] = useActionState(action, 'initial-state') return (
{`${state}`}
) } export class ErrorBoundary extends React.Component<{ children: React.ReactNode }> { state = { error: null } static getDerivedStateFromError(error) { return { error } } render() { if (this.state.error) { return (
Error boundary: {this.state.error.message}
) } return this.props.children } }