import type { FormHTMLAttributes } from "react"; import { forwardRef, useCallback } from "react"; export interface FormProps extends FormHTMLAttributes { /** * Boolean if the form should no longer prevent default submit behavior. If * you enable this prop you should honestly just use a `
` element * instead */ disablePreventDefault?: boolean; } /** * This is probably one of the least useful components available as it doesn't * do much styling or logic. All this form component will do is add basic flex * behavior and prevent the default form submit behavior. */ export const Form = forwardRef(function Form( { children, disablePreventDefault = false, onSubmit, ...props }, ref ) { const handleOnSubmit = useCallback>( (event) => { if (!disablePreventDefault) { event.preventDefault(); } if (onSubmit) { onSubmit(event); } }, [disablePreventDefault, onSubmit] ); return ( {children} ); });