Skip to content

Instantly share code, notes, and snippets.

@JoaoCnh
Created February 5, 2018 15:42
Show Gist options
  • Save JoaoCnh/49579bccaf9cd49a25155400a91207d1 to your computer and use it in GitHub Desktop.
Save JoaoCnh/49579bccaf9cd49a25155400a91207d1 to your computer and use it in GitHub Desktop.
Localization HOC for I18nProvider
import React, { Component } from "react";
import PropTypes from "prop-types";
const withI18n = ComponentToWrap => {
return class I18nComponent extends Component {
static contextTypes = {
t: PropTypes.func.isRequired,
locale: PropTypes.string.isRequired
};
render() {
const { t, locale } = this.context;
return <ComponentToWrap {...this.props} t={t} locale={locale} />;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment