Skip to content
Discussion options

You must be logged in to vote

If you want to submit the data when it is input, you should control the submit process.

export default function Component() {
  const formRef = useRef<HTMLFormElement>(null)
  const requestSubmit = useRef(false)
  const [form, fields] = useForm({
    constraint: getZodConstraint(FormSchema),
    onValidate({ formData }) {
      return parseWithZod(formData, { schema: FormSchema });
    },
    onSubmit() {
      console.log('onSubmit')

      if (!requestSubmit.current) {
        console.log('cancel submit')
        e.preventDefault()
        return
      }

      requestSubmit.current = false
      console.log('execute submit')
    },
  });

  const submitRef = useRef<HTMLInputElement>(null!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lhapaipai
Comment options

Answer selected by lhapaipai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants