Performance: useFetcher for non-navigation mutations
This affects how quickly the page responds to user actions without full page reloads, improving interaction speed and reducing unnecessary rendering.
import { useFetcher } from '@remix-run/react'; function GoodForm() { const fetcher = useFetcher(); return ( <fetcher.Form method="post" action="/submit"> <input name="data" /> <button type="submit">Send</button> </fetcher.Form> ); }
function BadForm() {
return (
<form method="post" action="/submit">
<input name="data" />
<button type="submit">Send</button>
</form>
);
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full form submit with navigation | Reloads entire DOM | Multiple reflows due to full reload | High paint cost for full page | [X] Bad |
| useFetcher for form submit | Minimal DOM updates | Single reflow for updated parts | Low paint cost | [OK] Good |
useFetcher in Remix?useFetcher is designed to send data or make requests without causing a page navigation or reload.useFetcher without navigation?fetcher.submit is the method designed to submit data without causing navigation.fetcher.navigate causes navigation, fetcher.reload reloads page, and fetcher.fetch is not a valid method.const fetcher = useFetcher();
return (
<fetcher.Form method="post" action="/api/update">
<input name="name" />
<button type="submit">Update</button>
</fetcher.Form>
);fetcher.Form submits data without causing navigation or reload, keeping user on the same page.useFetcher for a non-navigation mutation:const fetcher = useFetcher();
function handleClick() {
fetcher.submit({ name: 'Alice' });
}
return <button onClick={handleClick}>Send</button>;fetcher.submit needs two arguments: data and an options object specifying method and action.useFetcher to submit the form and handle the response to show a success message?fetcher.submit with form data and specifying method and action sends data without navigation.fetcher.data lets you react to server response and display a success message without reload.Pass the test and this pattern moves unknown