import React from 'react'
import useTranslation from './useTranslation'
import { NextComponentType } from 'next'
/**
* HOC to use the translations in no-functional components
*/
export default function withTranslation
(
Component: React.ComponentType
| NextComponentType,
defaultNS?: string
): React.ComponentType> {
const WithTranslation: NextComponentType = (props: P) => {
const i18n = useTranslation(defaultNS)
return
}
WithTranslation.getInitialProps = async (ctx) => {
const WrappedComponent = Component as NextComponentType
if (WrappedComponent.getInitialProps) {
return (await WrappedComponent.getInitialProps(ctx)) || {}
} else {
return {}
}
}
WithTranslation.displayName = `withTranslation(${
Component.displayName || ''
})`
return WithTranslation
}