2017-06-04 8 views
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; 
+0

代わりに 'this.props.children'、文字列の小道具の - ' this.props.text'がアップデートコンポーネントのために働く必要があります。 – vijayst

答えて

2

使用自動閉鎖構文bassingのより良い方法があります:

<textarea ref="newText" defaultValue={this.props.children}/> 

それとも実際に、あなただけのスペースを削除することができますが、 <textarea>タグも同様です。

+0

ありがとうTharakaそれは働いた –

関連する問題