Skip to content

fibo/react-intl-inject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-intl-inject

react-intl helper, can translate props easily

Installation

Make sure react-intl is installed, it is required as a peer dependency

npm i react-intl

Then install as usual

npm i react-intl-inject

Usage

Suppose you need to translate a prop, for instance the value of a submit button.

import React, { Component } from 'react'
import InjectIntl from 'react-intl-inject'

class MyComponent extends Component {
  render () {
    return (
      <InjectIntl>
        {({ intl }) => (
          <button
            type='submit'
            value={intl.formatMessage({ id: 'enter.submit' })}
          />
        )}
      </InjectIntl>
    )
  }
}

See also this Stack Overflow question.

License

MIT