Created
February 5, 2018 15:42
-
-
Save JoaoCnh/49579bccaf9cd49a25155400a91207d1 to your computer and use it in GitHub Desktop.
Localization HOC for I18nProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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