Skip to content

Basic Usage

Choose the right approach based on your use case:

Best for static flags known at build time.

  • Bundle impact: ~950 bytes per flag
  • Tree-shaking: ✅ Excellent
  • Loading: Synchronous, instant

Import only the flags you need from the main entry:

import { FlagUs, FlagCn, FlagGb } from '@sankyu/react-circle-flags'
export function Header() {
return (
<div>
<FlagUs width={32} height={32} />
<FlagCn width={32} height={32} />
<FlagGb width={32} height={32} />
</div>
)
}

Offline-first runtime flags (bundles all flags).

  • Bundle impact: ~600 KB
  • Tree-shaking: ❌ None
  • Loading: Synchronous, instant

Render any flag from runtime ISO codes without network requests:

import { DynamicFlag } from '@sankyu/react-circle-flags'
export function CountryFlag({ code }: { code: string }) {
return <DynamicFlag code={code} width={36} height={36} />
}

All flag components follow a consistent naming pattern:

Pattern

Components use the format Flag{ISO} where ISO is the uppercase country code.

Examples

  • FlagUs → United States

  • FlagCn → China

  • FlagGb → United Kingdom

  • FlagJp → Japan

The library works seamlessly with all modern frameworks:

import { FlagUs, FlagCn } from '@sankyu/react-circle-flags'
export default function Page() {
return (
<main>
<h1>Country Flags</h1>
<div className="flex gap-4">
<FlagUs width={64} height={64} />
<FlagCn width={64} height={64} />
</div>
</main>
)
}