[英]Calling component in input placeholder
I'm currently trying to call a React component in the position of a text placeholder, but It returns [Object object].我目前正在尝试在文本占位符的位置调用 React 组件,但它返回 [Object object]。 Below is the input
下面是输入
render(){
const myText = this.movingText();
<input placeholder={myText}/>
}
then this is the function I'm calling with the component typist tag.那么这是我用组件打字员标签调用的函数。
movingText() {
return (
<Typist>
Hello this is the text
</Typist>
)}
So I'm really trying to call the component and its contents as a placeholder.所以我真的试图将组件及其内容称为占位符。 Any help is much appreciated.
非常感谢任何帮助。 Thanks
谢谢
In your render...在你的渲染...
render(){
const myText = this.movingText();
return(
<input placeholder={myText}/>
)
}
Use renderToString from react as below使用 renderToString 从反应如下
import { renderToString } from 'react-dom/server';
const myText = renderToString(this.movingText());
return(
<input placeholder={myText}/>
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.