在我的渲染函数中
<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 只是不断将 client_lyrics 设置为自身。
如何使用值初始化文本区域,然后向其附加更多字符,以便 client_lyrics 属性实际发生变化?
最佳答案
在 textArea
上使用 onChange
而不是 onKeyUp
事件
<textarea value={ this.props.song.client_lyrics }
onChange={ (event) => this.props.editLyrics(event.target.value) } >
</textarea>
关于javascript - 在 redux 应用程序中初始化然后更新 textarea 值。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44207842/