我在 React 应用程序中使用i18n包来翻译一些文本。但我无法迭代作为我的翻译数据的对象数组。
我想迭代数组socials并将其显示在我的模板中。但当我这样做时,它说:socials.map is not a function
这是我的翻译 json 文件:
{
"socials": [
{
"name": "Github",
"url": "#"
},
{
"name": "Twitter",
"url": "#"
},
{
"name": "Linkedin",
"url": "#"
},
{
"name": "Instagram",
"url": "#"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的 jsx 代码:
import { useTranslation } from 'react-i18next';
const Content = () => {
const { t, i18n } = useTranslation();
const socials = t('socials', { returnObjects: true });
rerurn (
<div className="flex">
{socials.map((social) …Run Code Online (Sandbox Code Playgroud)