小编m_w*_*wer的帖子

如何在 React 中不使用 hook 来使用 i18n 翻译?

我需要在我的中间件(import { Middleware } from 'redux')逻辑中进行翻译,但我不能使用useTranslation钩子(import { useTranslation } from 'react-i18next')。您如何标准解决这种情况?

\n

错误信息:

\n
React Hook "useTranslation" is called in function "myFunction: Middleware<{}, RootStateType>" which is neither a React function component or a custom React Hook function.\n
Run Code Online (Sandbox Code Playgroud)\n

我的代码(缩短):

\n
import PushNotificationIOS from '@react-native-community/push-notification-ios';\nimport { Middleware } from 'redux';\nimport { getType } from 'typesafe-actions';\n\nconst scheduleNotificationSettings = (notification: NotificationT): void => {\n PushNotificationIOS.scheduleLocalNotification({\n        fireDate: notification.startDate,\n        alertTitle: TRANSLATE_SOMEHOW(notification.titleKey),<--- ! HERE ! \xc2\xaf\\_(\xe2\x80\xaf\xe2\x9d\x9b\xe2\x80\xaf\xcd\x9c\xca\x96 \xef\xb8\xa1\xe2\x9d\x9b)_/\xc2\xaf\n        alertBody: TRANSLATE_SOMEHOW(notification.bodyKey),  <--- …
Run Code Online (Sandbox Code Playgroud)

react-native react-redux react-i18next

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

react-i18next ×1

react-native ×1

react-redux ×1