I am using React-i18next library and I need to get a translation function t() inside of a function.
export function translateCell(cell) {
const { t } = useTranslation();
return (t(cell));
}
When using useTranslation() it fails with error
Hooks can only be called inside the body of a function component.
I tried to use I18nextProvider and also .use(initReactI18next) in initialization, but both setups produces same error.
Am I using it the wrong way, or have I misunderstood something?
EDIT: I found out, that only functions, that will be rendered as component can use useTranslation. Like
function export MyComponent (cell) {
const { t } = useTranslation();
return (<div>{t(cell)}</div>);
}
...
render(){
<MyComponent/>
react-dom? - samb102