Search code examples
jsxsolid-js

What is a `<form use:formSubmit`?


I am reading the SolidJS - Form Validation example which contains these snippets:

  const { validate, formSubmit, errors } = useForm({
    errorClass: "error-input"
  });

...
  const fn = (form) => {
    console.log("Done");
  };

<form use:formSubmit={fn}>
...

What is the <form use:? Can someone point me to some documentation? I am intrigued by it but I could not find an explanation. I am uncertain if that is SolidJS specific or JSX specific.


Solution

  • The syntax you are asking is called custom directive. It is a syntax sugar for refs, which means the compiled code calls the ref function with the underlying html element as the argument.

    https://www.solidjs.com/docs/latest/api#use___