【发布时间】:2023-05-16 13:14:01
【问题描述】:
我需要翻译我的应用程序,但我不知道如何在*文件中使用 useTranslation()(我在那里存储了一些包含一些文本的常量)。该文件之一是
import { useTranslation } from "react-i18next";
const {t} = useTranslation()
export const selectThemeOptions = [
{ value: "choose", text: "Choose theme" },
{ value: "Algebra", text: "Algebra" },
{ value: "Geometry", text: "Geomerty" },
{ value: "Programming", text: "Programming" },
{ value: "Logic", text: "Logic" },
];
所以在这种情况下我有一个错误: src\Configs\ThemesOfProblems.js 第 3:13 行:无法在顶层调用 React Hook “useTranslation”。 React Hooks 必须在 React 函数组件或自定义 React Hook 函数 react-hooks/rules-of-hooks 中调用
我的组件中需要这个数组,并在下一个片段中使用:
<Form.Group as={Col} controlId="problemTheme">
<Form.Label>{t("userprofile.theme")}</Form.Label>
<Form.Select
name="theme"
value={values.theme}
onChange={handleChange}
isValid={touched.theme && !errors.theme}
isInvalid={!!errors.theme}
onBlur={handleBlur}
>
{selectThemeOptions.map((el, index) => {
return <option key={index} value={el.value}> {el.text} </option>
})}
</Form.Select>
</Form.Group>
我遇到过很多这样的情况,我不知道该怎么做
【问题讨论】:
标签: javascript reactjs react-native internationalization i18next