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
- Host: GitHub
- URL: https://github.com/carloluis/use-intl-hook
- Owner: carloluis
- License: mit
- Created: 2019-08-21T21:14:34.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-02T18:56:58.000Z (over 6 years ago)
- Last Synced: 2024-08-09T02:36:17.288Z (almost 2 years ago)
- Topics: custom-hook, hooks, react, react-hooks, react-intl, reactjs
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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')
);
```