From 8a92584ccd2bfa38ca51dd979106daaa8d71b556 Mon Sep 17 00:00:00 2001 From: Jorn Luiten Date: Mon, 30 Sep 2019 10:25:04 +0200 Subject: [PATCH] Fix translate --- example/greeter.js | 2 +- src/translate.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/example/greeter.js b/example/greeter.js index bcd8515..f917c99 100644 --- a/example/greeter.js +++ b/example/greeter.js @@ -12,7 +12,7 @@ const Greeter = ({ name, nrCars, t }) => ( Greeter.propTypes = { name: PropTypes.string.isRequired, nrCars: PropTypes.number.isRequired, - t: PropTypes.func + t: PropTypes.func, } export default translate()(Greeter) diff --git a/src/translate.js b/src/translate.js index d835958..8a1974f 100644 --- a/src/translate.js +++ b/src/translate.js @@ -2,12 +2,15 @@ import React from 'react' import hoistNonReactStatics from 'hoist-non-react-statics' import I18nContext from './i18n-context' -export default function translate()(WrappedComponent) { - const _translate = props => ( - - {t => } - - ) +// higher order decorator for components that need `t` +export default function translate() { + return WrappedComponent => { + const _translate = props => ( + + {t => } + + ) - return hoistNonReactStatics(_translate, WrappedComponent) + return hoistNonReactStatics(_translate, WrappedComponent) + } }