无法使用replaceAll或替换为nextjs/reactjs

OSE*_*ATI 6 javascript reactjs next.js

我正在使用reactjs/nextjs,我目前正在尝试渲染此组件:

const Example = ({data}) => (
<strong>{() => data.slug.replaceAll("-", " ")}</strong>);
Run Code Online (Sandbox Code Playgroud)

我每次都会收到此错误:
TypeError: data.slug.replaceAll is not a function

slug 的类型是字符串,我检查了它。
我尝试使用data.slug.toString().replaceAll...在另一个 stackoverflow 答案中找到的内容,但我遇到了同样的问题。

我尝试使用函数而不是直接字符串,即:() => data.slug.replaceAll...,这次没有渲染。

我不知道这是否有帮助,但我尝试渲染的数据来自 api 通过getServerSideProps函数异步。

k.s*_*.s. 13

很可能是因为.replaceAll()并非所有浏览器都支持。

我可以用吗

目前,您可以使用简单的.replace()

data.slug.replace(/-/g, " ")
Run Code Online (Sandbox Code Playgroud)