TypeScript
All flag components are fully typed with TypeScript, providing autocomplete and type safety out of the box.
SVG prop typing
Section titled “SVG prop typing”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} />}Advanced typing examples
Section titled “Advanced typing examples”import type { SVGProps, ComponentProps } from 'react'import { FlagCn } from '@sankyu/react-circle-flags'
// Method 1: Using SVGPropstype FlagProps1 = SVGProps<SVGSVGElement>
// Method 2: Using ComponentProps (recommended)type FlagProps2 = ComponentProps<typeof FlagCn>
export function Flag(props: FlagProps2) { return <FlagCn {...props} />}import type { ComponentProps } from 'react'import { FlagUs, FlagCn, FlagGb } from '@sankyu/react-circle-flags'
type FlagComponent = typeof FlagUs | typeof FlagCn | typeof FlagGbtype FlagWrapperProps = ComponentProps<FlagComponent> & { label?: string}
export function FlagWithLabel({ label, ...flagProps }: FlagWrapperProps) { const FlagComp = flagProps.as || FlagUs return ( <div> <FlagComp {...flagProps} /> {label && <span>{label}</span>} </div> )}import type { MouseEvent } from 'react'import { FlagJp } from '@sankyu/react-circle-flags'
export function InteractiveFlag() { const handleClick = (e: MouseEvent<SVGSVGElement>) => { console.log('Flag clicked at', e.clientX, e.clientY) }
return ( <FlagJp width={48} height={48} onClick={handleClick} style={{ cursor: 'pointer' }} /> )}Type exports
Section titled “Type exports”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 codesconst validCode: FlagCode = 'us' // ✓ Validconst invalidCode: FlagCode = 'invalid' // ✗ Type error
// FlagComponentProps: Standard props for flag componentsconst props: FlagComponentProps = { width: 64, height: 64, className: 'my-flag',}Type safety with DynamicFlag
Section titled “Type safety with DynamicFlag”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> )}Next step
Section titled “Next step” Bundle Size & Tree-shaking Learn how to optimize your bundle size with proper import strategies