Skip to content

Commit

Permalink
Fix translate
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorn Luiten committed Sep 30, 2019
1 parent c5c6fac commit 8a92584
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example/greeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 10 additions & 7 deletions src/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => (
<I18nContext.Consumer>
{t => <WrappedComponent {...props} t={t} />}
</I18nContext.Consumer>
)
// higher order decorator for components that need `t`
export default function translate() {
return WrappedComponent => {
const _translate = props => (
<I18nContext.Consumer>
{t => <WrappedComponent {...props} t={t} />}
</I18nContext.Consumer>
)

return hoistNonReactStatics(_translate, WrappedComponent)
return hoistNonReactStatics(_translate, WrappedComponent)
}
}

0 comments on commit 8a92584

Please sign in to comment.