我需要在我的中间件(import { Middleware } from 'redux')逻辑中进行转换,但是我不能使用useTranslation挂钩(import { useTranslation } from 'react-i18next')。你如何标准地解决这种情况?
错误消息:
React Hook "useTranslation" is called in function "myFunction: Middleware<{}, RootStateType>" which is neither a React function component or a custom React Hook function.我的代码(简称):
import PushNotificationIOS from '@react-native-community/push-notification-ios';
import { Middleware } from 'redux';
import { getType } from 'typesafe-actions';
const scheduleNotificationSettings = (notification: NotificationT): void => {
PushNotificationIOS.scheduleLocalNotification({
fireDate: notification.startDate,
alertTitle: TRANSLATE_SOMEHOW(notification.titleKey),<--- ! HERE ! ¯\_( ❛ ͜ʖ ︡❛)_/¯
alertBody: TRANSLATE_SOMEHOW(notification.bodyKey), <--- ! HERE !
alertAction: 'view',
isSilent: false,
repeatInterval: 'week',
});
};
export const handleAction: Middleware<{}, RootStateType> = () => {
return next => {
return action => {
const result = next(action);
switch (action.type) {
case getType(create): {
createNotification(action.payload);
break;
}
case getType(delete): {
removeNotification(action.payload);
break;
}
default:
return result;
}
return result; //pass events to other middleware
};
};发布于 2021-04-27 21:28:34
我希望我正确地理解了你的问题,但我假设你已经初始化了i18n,所以在react组件之外不要使用钩子,只需像这样导入它:
import i18n from 'i18next';然后使用它:
i18n.t(youri18nKey);https://stackoverflow.com/questions/67283086
复制相似问题