
โ useFetcher
์๋๋ Remix์์ ์ฒ์ ๋ฑ์ฅํ ๊ธฐ๋ฅ์ด๊ณ , ๊ทธ ์ดํ React Router์ Data Router(6.4+)์ ๋ค์ด์ด.
ํ์ด์ง ์ด๋ ์์ด loader/action๋ง ํธ์ถํ๊ณ ์ถ๋ค. ๋ผ๋ ๋ชฉ์ ์ ์ํด ๋ง๋ค์ด์ง
1. ๊ธฐ์กด Form์ฒ๋ผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ(๋ฒํผ์ ๋๋ฌ submit ํ๋ ๋ฐฉ์)
const fetcher = useFetcher();
<fetcher.Form
method="POST"
action={`/community/${loaderData.post.post_id}/upvote`}
>
<input
type="hidden"
value={loaderData.post.post_id}
name="postId"
/>
<Button
variant="outline"
className={cn(
"flex h-14 flex-col",
loaderData.post.is_upvoted
? "border-primary text-primary"
: "",
)}
>
<ChevronUpIcon className="size-4 shrink-0" />
<span>{loaderData.post.upvotes}</span>
</Button>
</fetcher.Form>
2. ์ด๋ ํ event์๋ submit ํ๊ฒ ๋ง๋๋ ๋ฐฉ์
const fetcher = useFetcher();
const absorbClick = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
fetcher.submit(
{
postId: id,
},
{ method: "POST", action: `/community/${id}/upvote` },
);
};'๐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ๋ผ์ด๋ธ๋ฌ๋ฆฌ - React Email (0) | 2026.07.21 |
|---|---|
| ๋ผ์ด๋ธ๋ฌ๋ฆฌ - Cloudflared (0) | 2026.07.21 |
| ๋ผ์ด๋ธ๋ฌ๋ฆฌ - Supabase SSR Package, Auth (0) | 2026.06.10 |
| ๋ผ์ด๋ธ๋ฌ๋ฆฌ - React Router v7 - clientLoader, HydrateFallback (0) | 2026.05.29 |
| ๋ผ์ด๋ธ๋ฌ๋ฆฌ - React Router v7 - prefetch (1) | 2026.05.29 |