Skip to content

TypeScript

All flag components are fully typed with TypeScript, providing autocomplete and type safety out of the box.

All flag components accept standard React SVG props:

import type { SVGProps } from 'react'
import { FlagUs } from '@sankyu/react-circle-flags'
interface Props {
flagProps?: SVGProps<SVGSVGElement>
}
export function FlagItem({ flagProps }: Props) {
return <FlagUs {...flagProps} />
}
import type { SVGProps, ComponentProps } from 'react'
import { FlagCn } from '@sankyu/react-circle-flags'
// Method 1: Using SVGProps
type FlagProps1 = SVGProps<SVGSVGElement>
// Method 2: Using ComponentProps (recommended)
type FlagProps2 = ComponentProps<typeof FlagCn>
export function Flag(props: FlagProps2) {
return <FlagCn {...props} />
}

The library exports helpful types for advanced use cases:

import type { FlagCode, FlagComponentProps } from '@sankyu/react-circle-flags'
// FlagCode: Union type of all available flag codes
const validCode: FlagCode = 'us' // ✓ Valid
const invalidCode: FlagCode = 'invalid' // ✗ Type error
// FlagComponentProps: Standard props for flag components
const props: FlagComponentProps = {
width: 64,
height: 64,
className: 'my-flag',
}
import { DynamicFlag } from '@sankyu/react-circle-flags'
import type { FlagCode } from '@sankyu/react-circle-flags'
interface CountrySelectProps {
selectedCountry: FlagCode
onSelect: (code: FlagCode) => void
}
export function CountrySelect({ selectedCountry, onSelect }: CountrySelectProps) {
return (
<div>
<DynamicFlag code={selectedCountry} width={32} height={32} />
<button onClick={() => onSelect('us')}>USA</button>
<button onClick={() => onSelect('cn')}>China</button>
</div>
)
}