'use client'; import { type FC, type ReactNode, useCallback, useActionState } from 'react'; import { Notice } from '../Notice/Notice'; export interface FormState { error?: string, success?: string, } export interface FormProps { action: (state: State, payload: FormData) => Promise, initialState?: State, children: ReactNode, id?: string, } export const Form: FC> = ({ action, initialState, children, id }) => { const [state, formAction] = useActionState(action, initialState ?? {}); const showNotice = useCallback((notice: HTMLElement | null) => { notice?.scrollIntoView({ block: 'nearest' }); }, []); return (
{state.error && ( {state.error} )} {state.success && ( {state.success} )} {children}
); };