Skip to content

SWR로 자동 중복 제거

Overview

SWR enables request deduplication, caching, and revalidation across component instances.

Impact

  • Priority: MEDIUM-HIGH
  • Performance: automatic deduplication

Examples

Basic Usage

tsx
import useSWR from "swr"

function UserList() {
  const { data: users } = useSWR("/api/users", fetcher)
}

Immutable Data

tsx
import { useImmutableSWR } from "@/lib/swr"

function StaticContent() {
  const { data } = useImmutableSWR("/api/config", fetcher)
}

Mutations

tsx
import { useSWRMutation } from "swr/mutation"

function UpdateButton() {
  const { trigger } = useSWRMutation("/api/user", updateUser)
  return <button onClick={() => trigger()}>Update</button>
}

SWR Docs


Tags: client, swr, deduplication, data-fetching