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
| Name | Type | Description |
|---|---|---|
props | FlagProps | 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>"