import React, { forwardRef } from 'react';
import { FormProvider, FormHandles } from '@devesharp/unform-core';

export interface IFormProps {
   initialData?: object;
   children?: React.ReactNode;
   onSubmit: (data: any) => void;
}

export const UnformVirtual = forwardRef<FormHandles, IFormProps>(function Form(
   { initialData = {}, children, onSubmit, ...rest },
   formRef,
): any {
   return (
      <FormProvider ref={formRef} initialData={initialData} onSubmit={onSubmit}>
         <div {...rest}>{children}</div>
      </FormProvider>
   );
});
