![](/img/trans.png)
[英]How to pass props through this.props.children() not this.props.children
[英]How do I pass this.props.children to Textarea
我正在使用defaultValue在textarea中传递this.props.childred,但它给了我错误未捕获的错误:如果在上提供defaultValue
,则不要传递子级。
什么是另一种选择,或者有更好的方法来低音值
import React, {Component} from 'react';
class Update extends Component {
constructor(props){
super(props);
this.state = {
editing:false
}
this.renderEdit = this.renderEdit.bind(this)
}
edit(){
this.setState({
editing:true
})
}
remove(){
alert("remove")
}
save(){
this.setState({
editing:false
})
}
renderNormal(){
return (
<div className="container">
<div className="content"> {this.props.children}</div>
<button onClick={this.edit.bind(this)} className="edit" >Edit </button>
<button onClick={this.remove} className="remove" >Remove </button>
</div>
);
}
renderEdit(){
console.log( 'this.props ', this.props)
console.log( 'this.props.children ', this.props.children)
return (
<div className="container">
<textarea ref="newText" defaultValue={this.props.children} > </textarea>
<button onClick={this.save.bind(this)} className="edit" >Save </button>
</div>
);
}
render(){
var great = "awesome "
if(this.state.editing){
return this.renderEdit();
}else{
return this.renderNormal();
}
}
}
export default Update;
使用如下所示的自动关闭语法:
<textarea ref="newText" defaultValue={this.props.children}/>
或者实际上,您也可以删除<textarea>
标记之间的空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.