Skip to content

Instantly share code, notes, and snippets.

@emersonlaurentino
Created February 11, 2020 20:22
Show Gist options
  • Save emersonlaurentino/67307e4306a7a3f2e602a360de5380fe to your computer and use it in GitHub Desktop.
Save emersonlaurentino/67307e4306a7a3f2e602a360de5380fe to your computer and use it in GitHub Desktop.
React Intl with Hook
import React from 'react'
import { useIntl } from 'react-intl'
const AdminForm = () => {
const intl = useIntl()
return (
<form>
<label>
<small>{intl.formatMessage({ id: 'admin/username.form.label' })}</small>
<input />
</label>
<button type="submit">
{intl.formatMessage({ id: 'admin/username.form.submit' })}
</button>
</form>
)
}
export default AdminForm
@klzns
Copy link

klzns commented Feb 11, 2020

I would recommend using this method when possible instead:

import { FormattedMessage } from 'react-intl'

// ....inside the return of your component
  <FormattedMessage id="admin/username.form.label" />

@klzns
Copy link

klzns commented Feb 11, 2020

Also, there are many other components that can be used:
https://github.com/formatjs/react-intl/blob/master/docs/Components.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment