Skip to content

Commit

Permalink
Use Provider instead of contextType to fix hoist issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikkel committed Feb 4, 2019
1 parent e47d6a1 commit 70857c7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/hoc.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { I18nContext, I18nContextProps } from './context'
import { I18nContextProps } from './context'
import { I18nProvider } from './provider'
import { Omit } from './types'

export interface WithTranslateProps extends I18nContextProps {}
Expand All @@ -10,10 +11,12 @@ function withTranslate<P extends object>(
return class WithTranslate extends React.Component<P> {
static displayName = `withTranslate(${BaseComponent.displayName})`

static contextType = I18nContext

render() {
return <BaseComponent {...this.props} {...this.context} />
return (
<I18nProvider>
{i18nProps => <BaseComponent {...i18nProps} {...this.props} />}
</I18nProvider>
)
}
}
}
Expand Down

0 comments on commit 70857c7

Please sign in to comment.