Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass submit function to useForm composable #4777

Open
ayZagen opened this issue Jun 16, 2024 · 0 comments
Open

Pass submit function to useForm composable #4777

ayZagen opened this issue Jun 16, 2024 · 0 comments

Comments

@ayZagen
Copy link

ayZagen commented Jun 16, 2024

First of all, thanks for your support and great work.

Currently we provide form submit handler by passing it to handleSubmit function returned from useForm composable. Instead of calling it as a separate function, having a property in useForm argument would be more straightforward.

To give an example, instead of doing like this:

const { handleSubmit } = useForm( );

const onSubmit = handleSubmit( async ( values, ctx) => {
// ... submit logic
})

something like the following would be better for dx and will be more related to usage of useForm composable:

const { submitForm } = useForm({
  handleSubmit: async (values, ctx) => {
    // ... submit logic
  }
});

In order to prevent featuring this as a breaking change, the both ways could be available without contradicting each other.

Assuming the new interface is like the one above, following would work without any breaking change:

const { submitForm, handleSubmit } = useForm({
  handleSubmit: async (values, ctx) => {
    console.log('initial submit')
  }
});

const onSubmit = handleSubmit(async (values, ctx) => {
  console.log('overridden')
})

// onSubmit() // Prints: overridden
submitForm() // Prints: overridden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant