初始化然后在redux app中更新textarea值。

时间:2017-05-26 18:14:08

标签: javascript reactjs redux textarea

在我的渲染功能中,我有

     <textarea value={ this.props.song.client_lyrics }
               onKeyUp={ (event) => this.props.editLyrics(event.target.value) } >
     </textarea>

通常,editLyrics函数将调度更新client_lyrics的操作。但是因为我有value = {this.props.song.client_lyrics}而不是event.target.value发送初始值+我输入的内容,它只会继续发送原始的client_lyrics,它只是将client_lyrics设置为自己。

如何使用值初始化textarea,然后为其添加更多字符,以便client_lyrics prop实际更改?

1 个答案:

答案 0 :(得分:2)

onChange

上使用onKeyUp代替textArea事件
  <textarea value={ this.props.song.client_lyrics }
           onChange={ (event) => this.props.editLyrics(event.target.value) } >
 </textarea>
相关问题