1.0.0 • Published 6 years ago
react-i18n-hoc v1.0.0
react-i18n-hoc
Description
This is a higher order component to set i18n of your component.
Install
npm i react-i18n-hoc
License
This code has MIT license.
Example
/*********** FILE app.js ***********/
import ReactDOM from 'react-dom';
import MyComponent from './myComponent';
ReactDOM.render(
<MyComponent/>
,document.getElementById('app-root')
);
/*********** FILE myComponent.js ***********/
import { Component } from 'react';
import { I18N } from './react-i18n-hoc';
const lang = 'es';
const i18n = {
es: {
title: 'Prueba',
text: 'Esto es una prueba.'
},
en: {
title: 'Example',
text: 'This is an example'
},
}
@I18N({i18n})
export default class MyComponent extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h1>{this.props.i18n.title}</h1>
<p>{this.props.i18n.text}</p>
</div>
);
}
}
License
This code has MIT license.
1.0.0
6 years ago