reactjs - 如何使 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<
我要做的就是翻译密钥并将其传递给字符串道具。
解决方案
推荐阅读
- python - 完全约束最小二乘的向量化函数
- java - 如何添加其他目标作为自定义 Maven 插件的依赖项?
- c++ - 解析 RapidJSON 字符串在括号中返回 NULL
- grpc - 为什么浏览器不支持 gRPC?
- scala - Spark Structured Streaming + Kafka:当 Kafka 消息与 JSON 模式不匹配时,停止查询崩溃
- java - y/n 输入验证,包括无输入 Enter 键
- java - twitter 中的 twitter4j 状态有图像但没有媒体实体
- twitter-bootstrap - 添加动态多个引导选择字段
- php - Laravel:使用模型根据链接表返回数据库行。
- php - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) on Laravel Application