I use i18n package in my React application to translate some texts. But I can't iterate through an array of objects which is my translation data.
I want to do iterating through socials
array and show it in my template. but when I do that, it says: socials.map is not a function
this is my translation json file:
{
"socials": [
{
"name": "Github",
"url": "#"
},
{
"name": "Twitter",
"url": "#"
},
{
"name": "Linkedin",
"url": "#"
},
{
"name": "Instagram",
"url": "#"
}
]
}
this is my jsx code:
import { useTranslation } from 'react-i18next';
const Content = () => {
const { t, i18n } = useTranslation();
const socials = t('socials', { returnObjects: true });
rerurn (
<div className="flex">
{socials.map((social) => (
<a href={social.url}>{social.name}</a>
))}
</div>
);
}
export default Content;
How can I solve this problem?