reactjs - 如何在组件标题中使用翻译?
问题描述
我在一个项目中使用 react-translate-redux 进行国际化,但我不知道如何在组件的属性中使用翻译。具体来说,我希望将组件的标题文本国际化。
我会尝试以下,
<Button title={<Translate id="button">}>
但是Type 'Element' is not assignable to type 'string'
。
如何国际化标题文本?
解决方案
如果您想使用翻译组件,您不能将其作为道具传递,您必须将其作为子组件传递并this.props.children
在您的 Button Render 方法中渲染它。
如果 Button Component 是一个外部组件,您必须在 Flavor 2中使用类似这样的 prop 函数
推荐阅读
- java - Vaadin 更改文本字段标签颜色
- java - 如何获取运行 Spring Boot (Spring Web MVC) API(运行时)的 JVM 堆大小?
- asp.net - 将一个 asp 标签放在另一个标签下,它们之间没有空格
- java - 当互联网改变其状态时,Android RxJava 会通知
- azure - 在 Batch 帐户和池上安装的证书不适用于任务
- docker - 将 Kafka 连接嵌入 Ksqldb-server 时挂载(卷)不起作用
- angular - 编译@angular/core时导入意外符号ɵɵinvalidFactory,如何解决?
- java - 为什么在数组列表数组上使用 Arrays.fill() 时会出现意外行为?
- protocol-buffers - grpc:无法解组收到的消息原型:错误的线型
- mysql - 如何在mysql中使用select生成表达式