import React, { forwardRef, useCallback } from 'react'; import { getWebProps } from 'react-native-unistyles/web'; import { formStyles } from './Form.styles'; import { FormContext } from './FormContext'; import useMergeRefs from '../hooks/useMergeRefs'; import type { FormProps } from './types'; import type { IdealystElement } from '../utils/refTypes'; /** * Form component for managing form state and validation. * Wraps children in a context provider and renders a semantic
element on web. */ const Form = forwardRef(({ form, children, style, testID, id, }, ref) => { const handleSubmit = useCallback((e: React.FormEvent) => { e.preventDefault(); form.handleSubmit(); }, [form]); const containerProps = getWebProps([ formStyles.container, style as any, ]); const mergedRef = useMergeRefs(ref, containerProps.ref); return ( {children} ); }); Form.displayName = 'Form'; export default Form;