首页 > 解决方案 > 如何使 react-18next 的 t() 返回字符串

问题描述

我正在使用 typescript 和 react-18next 库进行翻译。
我有简单的组件,例如:

const Box = (props: {
  msg: string;
}): React.ReactElement<{ msg: string }> => { return <p>{props.msg}</p> }

我正在尝试像这样使用它:

<Box msg={t("common.message")} />

但我收到打字稿错误:

Argument of type '"common.message"' is not assignable to parameter of type 'TemplateStringsArray | Normalize<

我要做的就是翻译密钥并将其传递给字符串道具。

标签: reactjstypescriptreact-i18next

解决方案


推荐阅读