import { useContext , useCallback } from 'react' ; import { TranslationContext } from './TranslationContext' ; import { Translate } from '../types' ; see Polyglot . t link return { Function } example const useTranslate = ( ) : Translate => { const { i18nProvider , locale } = useContext ( TranslationContext ) ; const translate = useCallback ( ( key , options ? ) => i18nProvider . translate ( key , options ) as string , [ i18nProvider , locale ] ) ; return i18nProvider ? translate : identity ; } ; const identity = key => key ; export default useTranslate ;