Reactjs 如何在redux中更改按钮的文本

Reactjs 如何在redux中更改按钮的文本,reactjs,ecmascript-6,redux,Reactjs,Ecmascript 6,Redux,嗨,当我的按钮完成后,我需要更改它的文本。我想使用redux和es6。现在我的代码是 var TodoItem = React.createClass({ handleCompleted: function() { this.props.completeTodo(this.props.todo.id); }, handleDelete: function() { this.props.deleteTodo(this.props.todo.id); }, render: function() {

嗨,当我的按钮完成后,我需要更改它的文本。我想使用redux和es6。现在我的代码是

var TodoItem = React.createClass({
handleCompleted: function() {
this.props.completeTodo(this.props.todo.id);
},
handleDelete: function() {
this.props.deleteTodo(this.props.todo.id);
},
render: function() {
var textStyle = this.renderTextStyle();
return (
  <ul>
    <li>
      <div style={textStyle}>
        {this.props.todo.text}
      </div>
      <button onClick={this.handleCompleted}>toggle completed</button>
      <button onClick={this.handleDelete}>delete</button>
var TodoItem=React.createClass({
handleCompleted:函数(){
this.props.completeTodo(this.props.todo.id);
},
handleDelete:函数(){
this.props.deleteTodo(this.props.todo.id);
},
render:function(){
var textStyle=this.renderTextStyle();
返回(
  • {this.props.todo.text} 切换完成 删除

您需要一个状态值,可以将按钮文本绑定到该值。例如,如果您有一个
todo.isComplete
布尔值,则可以执行以下操作:

<button onClick={this.handleCompleted}>{ this.props.todo.isComplete ? 'undo' : 'complete' }</button>
{this.props.todo.isComplete?'undo':'complete'}
你的减速机可以设置
todo.isComplete
值。

我已经附上了我要做的图片(To do app**)。