Reputation: 833
I know how to use i18-next in react components, but right now what I want to do is that I want to import some data from my js file or json file, just for code separation, but I can't use useTranslation hook in those files, then what should I do ? here's what I want to achieve.
data.js
export const slideInfo = [
{
id:1,
img:"https://i.imgur.com/g2weSNQ.png",
title:t{"title"} //how to use something like const { t } = useTranslation() at here
},
{
id:2,
img:"https://i.imgur.com/g2weSNQ.png",
title:""
},
{
id:3,
img:"https://i.imgur.com/g2weSNQ.png",
title:""
},
]
Or the same thing in json file , I don't mind where the data is stored , just want to separate my code for readability.
Upvotes: 0
Views: 305
Reputation: 389
A possible solution would be:
export const getSlideInfo = (t) => [
{
id: 1,
img: 'https://i.imgur.com/g2weSNQ.png',
title: t('title'),
},
...
];
const ReactComponent = () => {
const { t } = useTranslation();
const slideInfo = getSlideInfo(t);
};
Upvotes: 1