diff --git a/packages/use-i18n/README.md b/packages/use-i18n/README.md index 52f8b756c..9dfdc6865 100644 --- a/packages/use-i18n/README.md +++ b/packages/use-i18n/README.md @@ -186,8 +186,8 @@ const App = () => { const { formatDate } = useI18n() const units = [ - formatDate(new Date(2020, 1, 13, 16, 28)) // "Feb 13, 2020" - formatDate(1581607680000, 'long') // "February 13, 2020" + formatDate(new Date(2020, 1, 13, 16, 28)), // "Feb 13, 2020" + formatDate(1581607680000, 'long'), // "February 13, 2020" formatDate('2020-02-13T15:28:00.000Z', { day: "numeric", era: "short", @@ -209,6 +209,35 @@ const App = () => { } ``` +### formatList + +This hook exposes a `formatList` function which can be used to format lists of strings. + +The first parameter is an array of strings to format. + +It accepts an `options` as second parameter which is an [Intl.ListFormat `options` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat). + +```js +import { useI18n } from '@scaleway/use-i18n' + +const App = () => { + const { formatList } = useI18n() + + const cities = [ + formatList(['Paris', 'New York', 'London']), // Paris, New York and London + formatList(['Paris', 'New York', 'London'], { + type: 'disjunction' + }) // Paris, New York or London + ] + + return ( +