Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id=react-container></div>
              
            
!

CSS

              
                .todo,.form{
  border:solid;
  margin:1em;
  border-color:gray;
}
.done{
  background-color:lightgreen;
}
.undone{
  background-color:tomato;
}
input,textarea,button{
  width:200px;
  margin:0.5em 1em;
}

              
            
!

JS

              
                class Main extends React.Component{
  constructor(){
    super()
    const todos=[
        
      ]
    this.state={
      todos:todos,
      count:todos.length+1,
    }
  }
    
  handleSubmit(e){
    e.preventDefault();
    const title = e.target.title.value;
    const desc = e.target.desc.value;
    const todos = this.state.todos.slice()
    const count = this.state.count
    
    todos.push({
      id: count,
      title: title,
      desc: desc,
      done: false,
    });
    this.setState({ todos:todos })
    this.setState({ count: count + 1 })
    
    e.target.title.value = '';
    e.target.desc.value = '';

  }
  setTodoStatus(target){
    const todos = this.state.todos.slice();
    const todo = todos[target.id-1];
    todo.done=!todo.done;
    todos[target.id-1]=todo;
    this.setState({todos});
  }
  render () {
    return(
      <div className="Main">
        <h1>Todo App</h1>
        <Form handleSubmit={this.handleSubmit.bind(this)} />
        <TodoList todos={this.state.todos} setTodoStatus={this.setTodoStatus.bind(this)}/>
      </div>
    );
  }
}

class TodoList extends React.Component{
  
  render () {
    const todos = this.props.todos.map(todo=>
          <Todo key={todo.id} {...todo} setTodoStatus={this.props.setTodoStatus}/>
    )
    return( 
      <div className="todoList">
        {todos}
      </div>
    );
  }
  
}

class Todo extends React.Component{
  render(){
    const className =  this.props.done ? "done todo" :"undone todo"
    const link = this.props.done ? "完了済み":"未達成"
    return(
      <div className={className}>
        <span> {this.props.id}</span>
        <span> : {this.props.title} </span>
        <a href="" onClick={(e)=>{e.preventDefault(); this.props.setTodoStatus(this.props)}}>{link}</a>
        <p>{this.props.desc}</p>
      </div>
    );
  }
  
}

class Form extends React.Component{
  render(){
    return(
      <div className="form">
        <form onSubmit={this.props.handleSubmit}>
          <input name="title" type="text" 
            placeholder="タイトルを記入してください(必須)"/>
          <br/>
          <textarea name="desc" placeholder="説明記入欄" />
          <br/>
          <button type="submit">Todoを作成</button>
        </form>
      </div>
    );
  }
}

     
ReactDOM.render(< Main />, document.getElementById('react-container'));   
              
            
!
999px

Console