运行 React.Intl <FormattedMessage> 函数

Run function on React.Intl <FormattedMessage>

我正在尝试 运行 一个函数来对 FormattedMessage 的结果进行进一步的字符串操作。即使在 运行 通过下面的函数将其设置为 :

之后,我也找不到方法
<Button text={ this.testMethod(buttonText) } />

testMethod(result){
 return result;
}

总结:我正在尝试获取实际文本而不是对象,然后进行一些字符串操作。

不想要这个: {id: "test", defaultMessage: "你好"}

需要:访问“Hello there”,例如提取单词“there”

是的,你可以。添加一个组件作为 FormattedMessage 的子组件以进行进一步的转换。这是让您开始使用的最小片段

<FormattedMessage id="hello">
  {(text) => {
    console.log(text);
    return <>{text.toUpperCase()}</>;
  }}
</FormattedMessage>

实例