This package has been deprecated

Author message:

use useContext(IntlContext) with npm install react-intl@next

use-react-intl
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Installation

npm install use-react-intl

Makes react-intl to be used as a Function component hook.

This module can be used temporarily until react-intl supports the React 16.3 Context API.

After that, it is better to use React 16.8 useContext() hook.

Usage

import React from 'react';
import { IntlProvider } from 'use-react-intl';
import { App } from './app';
 
export function Main(locale: 'en' | 'ko', messages: {[messageId: string]: string}) {
  return (
    <IntlProvider locale={locale} messages={messages}>
      <App/>
    </IntlProvider>
  )
}

First, you need to add <IntlProvider/> to your app.

Its usage is the same as <IntlProvider/> in react-intl.

import React from 'react';
import { InjectedIntl } from 'react-intl';
import { useIntl } from 'use-react-intl';
 
export function Component() {
  const intl: InjectedIntl = useIntl();
  
  return (
    <span>
      {intl.formatMessage({id: 'some.intl.text'})}
    </span>
  )
}

Then, you can use a hook function useIntl().

Package Sidebar

Install

npm i use-react-intl

Weekly Downloads

6

Version

0.1.2

License

MIT

Unpacked Size

3.95 kB

Total Files

4

Last publish

Collaborators

  • ssen