npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-react-emoji-flag

v1.0.3

Published

[![npm version](https://badge.fury.io/js/ts-react-emoji-flag.svg)](https://www.npmjs.com/package/ts-react-emoji-flag) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

Readme

ts-react-emoji-flag

npm version License: MIT

Display country flags using Unicode emoji - no images or SVGs required, works even on Windows!

Overview

The most efficient way to display country flags in React applications - using Unicode emoji characters directly. Supports all modern browsers and operating systems.

Example: "🇨🇭" (If this looks like a Swiss flag, your system supports emoji flags natively)

Installation

npm install ts-react-emoji-flag
# or
yarn add ts-react-emoji-flag

Usage

Basic Component Usage

import CountryFlag from 'ts-react-emoji-flag';

function MyComponent() {
  return <CountryFlag countryCode="US" title="United States" />;
}

Alternative Usage with Hook and Function

import { useCountryFlag, flag } from 'ts-react-emoji-flag';

function MyComponent() {
  // Initialize the flag support
  useCountryFlag({ className: "country-flag" });

  return (
    <div className="country-flag">
      {flag("JP")} Japan
    </div>
  );
}

API Reference

CountryFlag Component

<CountryFlag 
  countryCode="FR"       // Required: ISO 3166-1 alpha-2 country code
  title="France"         // Optional: Text for the title attribute
  className="my-flag"    // Optional: Additional CSS class
  forceLoadFont={false}  // Optional: Force custom font loading even on systems with native support
/>

useCountryFlag Hook

useCountryFlag({
  className: "country-flag",  // Optional: CSS class name (default: "country-flag")
  forceLoadFont: false        // Optional: Force custom font loading
});

flag Function

flag("DE"); // Returns a JSX element with the German flag emoji

TypeScript Support

This library includes TypeScript definitions. Example usage with TypeScript:

import CountryFlag, { useCountryFlag, flag } from 'ts-react-emoji-flag';

const MyComponent: React.FC = () => {
  return <CountryFlag countryCode="CA" title="Canada" />;
};

Windows Compatibility

On Windows, which doesn't natively display country flags from Unicode, the library automatically loads a special font to ensure proper flag display. You don't need to do anything extra for this feature to work.

If you want to force the custom font loading even on systems with native support, use the forceLoadFont prop:

<CountryFlag countryCode="IT" forceLoadFont={true} />

How It Works

The library:

  1. Converts country codes to their corresponding Unicode flag sequence
  2. Automatically detects if you're on Windows
  3. Loads a special font only when needed for compatibility
  4. Applies the appropriate CSS to ensure proper display

Credits

Inspired by country-flag-emoji-polyfill

Fork

This project is a fork of react-country-flag