1.0.0-beta.2 • Published 2 years ago

@calmdownval/intl-preact v1.0.0-beta.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Intl-Preact

@calmdownval/intl bindings for Preact.

Installation

# NPM
npm i @calmdownval/intl @calmdownval/intl-preact

# Yarn
yarn add @calmdownval/intl @calmdownval/intl-preact

Both packages already contain TypeScript declarations.

Usage

First add a top-level provider to load a locale:

import { IntlProvider } from '@calmdownval/intl-preact';
import { h } from 'preact';

export const App = () => (
  <IntlProvider url='/path/to/locale.json'>
    ...app contents
  </IntlProvider>
);

Then use the intl hook within components:

import { useIntl } from '@calmdownval/intl-preact';
import { h } from 'preact';

export const SubmitButton = () => {
  const { t } = useIntl();
  return (
    <button type='submit'>
      {t('form.submit')}
    </button>
  );
};