An open API service indexing awesome lists of open source software.

https://github.com/carloluis/use-intl-hook

react use-intl-hook for react-intl
https://github.com/carloluis/use-intl-hook

custom-hook hooks react react-hooks react-intl reactjs

Last synced: 5 months ago
JSON representation

react use-intl-hook for react-intl

Awesome Lists containing this project

README

          

# use-intl-hook

> React `use-intl-hook` for [react-intl](https://github.com/formatjs/react-intl).

:information_source: Now, you can simply use the `useIntl` available on react-intl. Check the API docs [here](https://github.com/formatjs/react-intl/blob/master/docs/API.md#useintl-hook)

## Install

```bash
yarn add use-intl-hook
```

## Usage

```jsx
import 'intl';
import React from 'react';
import ReactDOM from 'react-dom';
import { IntlProvider, addLocaleData } from 'react-intl';
import { InjectIntlContext, useIntl } from 'use-intl-hook';

import { locale, messages } from './i18n';

const Example = () => {
// call the useIntl hook to get the intl object from react-intl
const intl = useIntl();
return

{intl.formatMessage({ id: 'salutation' })}

;
};

// Include `InjectIntlContext` up in the tree to store the intl object from react-intl
ReactDOM.render(




,
document.querySelector('#app')
);
```