javascript - How to get value from contentEditable in reactjs -


i'm new reactjs. looking value inside <div> when contenteditable set true.

const listresults = this.state.results['1'].map((result) =>   <div key={result.tostring()} contenteditable="true">     {result}   </div> );  return (   <h1> listresults </h1>   <div> {listresults} </div> ) 

i outputting list pre-filled text-boxes allows user edit them. looking add in button once clicked captures data inside of text-boxes. can point me in direction on how capture changed data.

it may worth noting using reactjs on client side through cdn.

to value of editable div:

class app extends react.component {     constructor(){         super();       this.state = {             arr: [1,2,3,4,5]       }       this.change = this.change.bind(this);   }   change(e, index){     let tmparr = this.state.arr;     tmparr[index] = e.target.textcontent;     this.setstate({arr: tmparr})   }   render(){     console.log(this.state);     return (       <tr>           {this.state.arr.map((el, index) => <td key={index} id="test" onblur={(e) => this.change(e, index)} contenteditable="true">{el}</td>)}       </tr>     );   } } 

https://jsfiddle.net/69z2wepo/84647/

one note, can't return 2 elements on same level:

return (   <h1> listresults </h1>   <div> {listresults} </div> ) 

it should wrapped this:

return (     <div>       <h1> listresults </h1>       <div> {listresults} </div>     </div> ) 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -