5.0.4 • Published 5 months ago

use-formatted-message v5.0.4

Weekly downloads
4
License
ISC
Repository
github
Last release
5 months ago

Install

npm install --save use-formatted-message

API

https://christophehurpeau.github.io/use-formatted-message/

Why use this ?

This hook uses useMemo to avoid recall intl.formatMessage at each render, like FormattedMessage component.

Usage

import { defineMessages } from 'react-intl';
import useFormattedMessage from 'use-formatted-message';

const messages = defineMessages({
  title: {
    id: 'some.key.title',
    defaultMessage: 'This is the title content',
  },
  titleWithParams: {
    id: 'some.key.titleWithParams',
    defaultMessage: 'This is the title content, with {count}',
  },
});

function MyComponent({ count = 1 }) {
  const title = useFormattedMessage(messages.title);
  const titleWithParams = useFormattedMessage(
    messages.titleWithParams,
    { count },
    [count],
  );

  return (
    <div>
      <span title={title}>Hello</span>{' '}
      <span title={titleWithParams}>World</span>
    </div>
  );
}
5.0.4

5 months ago

5.0.3

7 months ago

5.0.2

8 months ago

5.0.1

8 months ago

5.0.0

9 months ago

4.1.0

1 year ago

4.0.0

1 year ago

2.0.0

2 years ago

1.0.0

4 years ago

0.0.0

4 years ago