Open this example in the interactive library
Live preview
Source code
// CollectionView.tsx
export default function CollectionView() {
const rows = [
{ key: "home", en: "Home", fr: "Accueil" },
{ key: "save", en: "Save", fr: "Enregistrer" },
{ key: "help", en: "Help", fr: "" },
];
const result = Object.fromEntries(rows.map((r) => [r.key, r.fr || r.en]));
const entries = Object.entries(
typeof result === "object" && result !== null ? result : { value: result },
);
return (
<section>
<h2>{"Build a locale dictionary with fallback text"}</h2>
{entries.length ? (
<dl>
{entries.map(([key, value]) => (
<div key={key}>
<dt>{key}</dt>
<dd>
{typeof value === "string" ? value : JSON.stringify(value)}
</dd>
</div>
))}
</dl>
) : (
<p>No matching entries.</p>
)}
</section>
);
}
