1
defaultValueを使用してthis.props.childredをtextareaに渡していますが、エラーが発生します。 未知のエラー:defaultValue
を入力すると、子を渡さないでください。Textboxにthis.props.childrenを渡すにはどうすればいいですか?
何他の代替であるか、またはこのような値
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;
代わりに 'this.props.children'、文字列の小道具の - ' this.props.text'がアップデートコンポーネントのために働く必要があります。 – vijayst