import * as React from 'react' import {useForm} from 'react-hook-form' import Method from './Method' type Props = { method: Method, action: string, href?: string, headers?: Record, onResponse?: (...args: unknown[]) => unknown, onError?: (...args: unknown[]) => unknown, onSubmit?: (...args: unknown[]) => unknown, children: (...args: unknown[]) => unknown, } const Form: React.FC = ({ method, action, href, children, onResponse, onError, headers, onSubmit, }) => { const onFormSubmit = async (body) => { const response = await fetch(href, { method, body, headers, }) const data = await response.json() if (typeof (onResponse as unknown) === 'function') { onResponse(data) } } const {register, handleSubmit} = useForm() return (
{children({ register })}
) } export default Form