Parsing 解析react标记的主体
假设我们有:Parsing 解析react标记的主体,parsing,reactjs,tags,Parsing,Reactjs,Tags,假设我们有: class Email extends React.Component{ constructor(props){ super(props); } validate(){ return true; } render(){ <input placeholder={this.is.what.i.ask.for.to.be.parsed.from.its.body} onFocus={this.validate
class Email extends React.Component{
constructor(props){
super(props);
}
validate(){
return true;
}
render(){
<input placeholder={this.is.what.i.ask.for.to.be.parsed.from.its.body} onFocus={this.validate} />
}
}
class电子邮件扩展React.Component{
建造师(道具){
超级(道具);
}
验证(){
返回true;
}
render(){
}
}
现在,当我恢复时,我想打电话:
<Email >
someone@company.com
</Email>
someone@company.com
如何解析someone@company.com
来自电子邮件
标签的正文
我知道这可以通过调用
来完成&我必须通过this.props.holder
更新render
因此,我们通过
this.props
访问React属性,但是,是否有内置方式访问它的主体 如果我理解正确,那么您应该使用这个.props.children
:
render() {
return (<input placeholder={this.props.children} onFocus={this.validate} />);
}
如果我理解正确,那么您应该使用
this.props.children
:
render() {
return (<input placeholder={this.props.children} onFocus={this.validate} />);
}
this.props.children
允许您访问组件的子级。在这种情况下,电子邮件地址内容将被视为email
组件的子级
最好使用该实用程序来确保只有一个孩子
像这样的方法应该会奏效:
class Email extends React.Component{
constructor(props){
super(props);
}
validate(){
return true;
}
render(){
return <input placeholder={React.Children.only(this.props.children)} onFocus={this.validate} />;
}
}
class电子邮件扩展React.Component{
建造师(道具){
超级(道具);
}
验证(){
返回true;
}
render(){
返回;
}
}
此.props.children
允许您访问组件的子级。在这种情况下,电子邮件地址内容将被视为email
组件的子级
最好使用该实用程序来确保只有一个孩子
像这样的方法应该会奏效:
class Email extends React.Component{
constructor(props){
super(props);
}
validate(){
return true;
}
render(){
return <input placeholder={React.Children.only(this.props.children)} onFocus={this.validate} />;
}
}
class电子邮件扩展React.Component{
建造师(道具){
超级(道具);
}
验证(){
返回true;
}
render(){
返回;
}
}
Nice,React.Children.只有
看起来有用。Nice,React.Children.只有
看起来有用。谢谢。。最后一点,我已经使用:[].forEach((方法)=>{this[method]=this[method].bind(this);})注入了this
。&您一定会理解我为什么这样做的…:)谢谢你。。最后一点,我已经使用:[].forEach((方法)=>{this[method]=this[method].bind(this);})注入了this
。&您一定会理解我为什么这样做的…:)