forge42dev / remix-hook-form

Open source wrapper for react-hook-form aimed at Remix.run
MIT License
330 stars 27 forks source link

`react-hook-form` interface mismatch #106

Closed raulfdm closed 1 month ago

raulfdm commented 1 month ago

Hey peeps. 👋

First, thanks for this library.

I'm trying to to migrate from remix-hook-form 4 to 5 and I notice now, the handleSubmit handler we get from useRemixForm requires a FormEvent.

I found the commit that had implemented that (https://github.com/forge42dev/remix-hook-form/commit/63f34aaa70e193668040acb97fd6cdf7a81de271) saying The one where remix-hook-form respects Form props, but... is that true?

I mean, the react-hook-form handleSubmit handler seems not to require a FormEvent (well, at least it's what it seems looking this interface

Also, if we use straight the react-hook-form:

import {useForm} from 'react-hook-form'

//.... using the hook
  const reactForm = useForm({
    resolver: async (data) => {
      return {
        values: data,
        errors: {},
      };
    },
  });

 // calling the factory to handle the handleSubmit
  const actualHandleSubmit = reactForm.handleSubmit(console.log, console.log);

  // form event is optional
  actualHandleSubmit()

We can call the actualHandleSubmit without passing any event.

I'm raising this issue because I've built forms out of the <Form> logic (within modals, lifting the remixForm up, etc) where I was simply calling methods.handleSubmit and the action trigger had happened inside the onValid hook where I massage the data and use the fetcher.

In summary, my question here is simple: is the event really required? If I pass an empty object would impact anyhow in the code?