Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Parsing 解析react标记的主体_Parsing_Reactjs_Tags - Fatal编程技术网

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
。&您一定会理解我为什么这样做的…:)