I see that in React you can pass a function to the action prop of the <form>
, for example:
<code><form action={search}>
<input name="query" />
<button type="submit">Search</button>
</form>
</code>
<code><form action={search}>
<input name="query" />
<button type="submit">Search</button>
</form>
</code>
<form action={search}>
<input name="query" />
<button type="submit">Search</button>
</form>
Source: https://react.dev/reference/react-dom/components/form
How does it differ from onSubmit
, and what would be the best practice (in React) ?