Skip to the content

Hata旗

Load a native country or region flag, choose supported framing and keep each drawing’s source, author and licence.

Hata (旗) is Japanese for a flag. About the name

Contents

Reference · /react

useFlagfunction

The flag of a component's props, as a hook: the flag if it is already loaded (preloadFlags), else it is loaded: React 19 suspends until it is, and React 18 draws nothing until an effect has loaded it.

Import it

import { useFlag } from "@johnmorrisdotca/hata/react";

Definition

function useFlag(props: FlagProps): BoundFlag | null

Parameters

NameTypeDescription
propsFlagProps

The flag, as the element's attributes give it.

Returns

BoundFlag | null

The flag to draw, or null when there is none (or, in React 18 with nothing preloaded, none yet).

Examples

import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { preloadFlags, useFlag } from "@johnmorrisdotca/hata/react";

await preloadFlags([{ code: "JP" }]);
const Name = () => createElement("b", null, useFlag({ code: "JP" })?.name);
console.log(renderToStaticMarkup(createElement(Name))); // "<b>Japan</b>"

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/hata 1.31.0.