Listing Items in React with Intl.ListFormat
Intl.ListFormat turns an array into a string such as りんご、みかん、ぶどう. In English, it produces Apple, Orange, and Grape, with "and" before the last item. You do not need to write the separators and words such as "and" or its equivalent in each language yourself.
In React, create the formatter once outside the component, or recreate it with useMemo only when the language changes. To list items while keeping them as JSX, for example to make them bold, use formatToParts().
The test environment was Ubuntu 24.04, Node.js 22.23.4 (ICU 78.3), and Chromium 153. I used react / react-dom 19.3.1, @types/react 19.3.0, typescript 7.0.2, esbuild 0.28.2, and Playwright 1.63.0. I type-checked the .tsx files with tsc, transformed them with esbuild, and ran them in a development build. The browser was opened with Playwright, with the language set to Japanese. I did not test Firefox, Safari, or production builds.
- 1. Create a formatter and pass an array to format()
- 2. In English, the language setting changes even the commas
- 3. To switch languages, recreate the formatter with useMemo
- 4. With zero items, the output is an empty string
- 5. Only strings can be passed
- 6. Use formatToParts to list bold text or links
- 7. Summarize the third and later names as "and N others"
- 8. Match the results on the server and in the browser
Create a formatter and pass an array to format()
Create a formatter with new Intl.ListFormat(), passing a language and a type, then pass an array of strings to format() (MDN: Intl.ListFormat() constructor). The type can be conjunction (the default), which lists everything as "A, B, and C"; disjunction, which joins with "or"; or unit, which lists values with units as a single unit.
If the language is fixed, create the formatters at module level and reuse them.
// Create the formatters once in the module and reuse them
const and = new Intl.ListFormat('ja-JP', { type: 'conjunction' });
const or = new Intl.ListFormat('ja-JP', { type: 'disjunction' });
export const formatAnd = (items: string[]) => and.format(items);
export const formatOr = (items: string[]) => or.format(items);
These are the results I got in Node.js:
| Input array | formatAnd |
formatOr |
|---|---|---|
['りんご', 'みかん', 'ぶどう'] |
りんご、みかん、ぶどう |
りんご、みかん、またはぶどう |
['りんご', 'みかん'] |
りんご、みかん |
りんごまたはみかん |
['りんご'] |
りんご |
りんご |
[] |
empty string | empty string |
With conjunction in Japanese, even two items did not get the particle と, so the output was りんご、みかん. If you want りんごとみかん, Intl.ListFormat cannot produce it, so you need to build that string yourself.
type: 'unit' is for listing quantities such as 1時間30分. With style: 'narrow', the output was 1時間30分. With long and short, a space was inserted, giving 1時間 30分.
In English, the language setting changes even the commas
The same array produces different separators depending on the language. These are the results for ['Apple', 'Orange', 'Grape'].
| Language | conjunction |
disjunction |
|---|---|---|
en-US |
Apple, Orange, and Grape |
Apple, Orange, or Grape |
en-GB |
Apple, Orange and Grape |
Apple, Orange or Grape |
de-DE |
Apple, Orange und Grape |
Apple, Orange oder Grape |
en-US puts a comma before "and", and en-GB does not. These results match the Oxford comma example in the MDN constructor documentation. With two items in en-US, the output was Apple and Orange.
Changing style with en-US
conjunction gave Apple, Orange, & Grape with short, and Apple, Orange, Grape with narrow. With ja-JP
conjunction, all three style values gave りんご、みかん、ぶどう.
To switch languages, recreate the formatter with useMemo
If the user can switch languages on screen, cache the formatter with useMemo and recreate it only when the language or type changes (React docs: useMemo).
import { useMemo } from 'react';
// Recreate the formatter only when the language or type changes
export function useListFormat(
locale: string,
type: Intl.ListFormatType = 'conjunction',
): Intl.ListFormat {
return useMemo(() => new Intl.ListFormat(locale, { type }), [locale, type]);
}
For testing, I built a screen that calls this hook twice, once with conjunction and once with disjunction, and lists the fruits selected with checkboxes. I added a counter to the hook to count how many formatters were created. On the first render, the count was 2. It stayed at 2 after re-rendering three times with a button and after toggling checkboxes. When I switched the page to English, the count went to 4, and switching back to Japanese brought it to 6, so both formatters were recreated each time the language changed.

The React docs say that useMemo is a performance optimization, and that React may throw away the cache and recompute it. This does not cause a problem here, because recreating the formatter gives the same result.
With zero items, the output is an empty string
When all checkboxes were unchecked, format() returned an empty string, and that part of the screen was blank. To show a message such as "No items selected", check whether the array is empty first.
<p id="and">{selected.length > 0 ? and.format(selected) : '選んでいません'}</p>
In the test screen, unchecking all items showed 選んでいません (meaning "Nothing selected") in that part only.
Only strings can be passed
format() accepts an iterable, such as an array, whose elements are strings (MDN: format()). In Node.js, passing an array of numbers, [1, 2], threw TypeError: Iterable yielded 1 which is not a string at runtime. TypeScript reports the error at type-check time:
typecheck/numbers.ts(2,10): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'Iterable<string>'.
To list numbers, convert them to strings first, for example with [1, 2].map(String). The result was 1、2.
A string is also an iterable of characters, so passing 'abc' by mistake does not cause a type error. It was split into single characters and produced a、b、c.
Also, if lib in tsconfig.json stays at es2020, TypeScript cannot find Intl.ListFormat and reports Property 'ListFormat' does not exist on type 'typeof Intl'. ... Try changing the 'lib' compiler option to 'es2021' or later. Set lib to es2021 or later. I used es2022 in the test.
Use formatToParts to list bold text or links
format() returns a string, so it cannot wrap items in <strong> or links. formatToParts() returns an array split into items (element) and separators (literal) (MDN: formatToParts()). For ['A', 'B', 'C'], ja-JP returned 、 as a literal, and en-US returned , and , and .
So the code passes numbered strings to the formatter instead of the items, then puts the original JSX back in place of each element part.
import type { ReactNode } from 'react';
type Props = {
items: ReactNode[];
format: Intl.ListFormat;
};
// Keep the items as JSX and let the formatter provide only the separators such as "、" or "and"
export function FormattedList({ items, format }: Props) {
// Pass numbered strings to the formatter instead of the items
const parts = format.formatToParts(items.map((_, i) => String(i)));
return (
<>
{parts.map((part, i) =>
part.type === 'element' ? (
<span key={i}>{items[Number(part.value)]}</span>
) : (
<span key={i}>{part.value}</span>
),
)}
</>
);
}
To use it, pass an array of JSX elements as items.
<FormattedList items={selected.map((f) => <strong key={f}>{f}</strong>)} format={and} />
The HTML rendered in Chromium is shown below. Only the separator 、 appeared outside the bold tags.
<span><strong>りんご</strong></span><span>、</span><span><strong>みかん</strong></span><span>、</span><span><strong>ぶどう</strong></span>
After switching to English, the same component displayed Apple, Orange, and Grape. The component distinguishes the separators by type, so you do not need separate code for each language.
Summarize the third and later names as "and N others"
When there are many names and you want to show only the first few, add the number of remaining names as the last item before formatting the list.
// Format only the first max items and summarize the rest as "N others"
export function formatNames(names: string[], max: number): string {
if (names.length <= max) return and.format(names);
const rest = names.length - max;
return and.format([...names.slice(0, max), `他${rest}人`]);
}
With five names and max set to 2, the output was 佐藤、鈴木、他3人. With two names, the output was 佐藤、鈴木. Intl.ListFormat does not generate the "and N others" phrase, so if you need English support too, prepare a separate sentence for each language.
Match the results on the server and in the browser
If you omit the language, the default language of the environment is used (MDN: locales argument). In the test environment, new Intl.ListFormat() used en-US in Node.js and ja-JP in Chromium with Japanese settings, so the default languages did not match.
I used 'ja-JP' explicitly in the code for this article. I compared the HTML rendered by renderToString in Node.js with the HTML rendered in Chromium at four places where lists are displayed: conjunction, disjunction, bold, and "and N others". They were identical in all four. For server-rendered screens, also specify the language instead of omitting it.
However, the MDN format() documentation notes that output can differ between implementations even for the same language, and advises against comparing it with a fixed string.





