Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//fb.me/react-0.13.1.js"></script>
  <meta charset="utf-8">
  <title>React Hello World w/ JSBin</title>
</head>
<body>
  <div id="react_example"></div>
</body>
</html>
 
class Todo extends React.Component {
  constructor(){
    super()
    this.data = ['write book','wash clothes','jogging'];
  }
  render() {
    return (      
      <div>
        <ul>
         {this.data.map((item)=><TodoItem key={item} item={item}/>)}
        </ul>
      </div>
    ); 
  }
}
class TodoItem extends React.Component {
  constructor(){
    super()
    this.state = {
      text: '',
      isEditing: false
    };
    this.onClickEdit = this.onClickEdit.bind(this);
    this.onSaveEdit = this.onSaveEdit.bind(this);
    this.onTextChanged = this.onTextChanged.bind(this);
  }
  onClickEdit(){
    this.setState({isEditing: !this.state.isEditing});
  }
  onSaveEdit(){
    this.setState({
      text: this.state.text, 
      isEditing: false
    });
  }
  onTextChanged(e){
    this.setState({text: e.target.value});
  }
  render(){
    return(
      
      <li>
      {this.state.isEditing ? '' : <span>{this.props.item}</span>}
      
      {this.state.isEditing ? <span><input value={this.props.item} type="text" onChange={this.onTextChanged}/></span> :''}
      &nbsp;&nbsp;
      {this.state.isEditing ? '' : <button onClick={this.onClickEdit}>Edit</button>}
      
      <button onClick={this.onSaveEdit}>Save</button>
      </li>
    )
  }
}
React.render(
  <Todo/>,
  document.getElementById('react_example')
);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers