• Skip to content
  • Skip to primary sidebar

Developers Tips & Tricks

You are here: Home / React JS / React JS TODO LIST

React JS TODO LIST

7 abril, 2016 by MPezzolano

Todo App. A simple way to work with de dom.

We will create a simple form with one text field and a submit button, using the method React.createClass,

so let’s do it :

We have two classes, one for create every task and other for refresh every task on the browser.

We can show items using map function javascript, in this way we can use  class A  calling class B

Create TODO LIST with React JS

We just generate index.html like this :

1
2
3
4
5
6
7
8
9
10
11
<html>
  <head>
    <title>Lista de tareas con React</title>
    <script src=“https://fb.me/react-0.13.3.js”></script>
    <script src=“https://fb.me/JSXTransformer-0.13.3.js”></script>
  </head>
  <body>
    <div id=“content”></div>
    <script type=“text/jsx” src=“form.jsx”></script>
  </body>
</html>

And after we generate other file called form.jsx.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//class for create todo list
var TodoList = React.createClass({
    render: function()
    {
        var createItem = function(itemText, index)
        {
            return <li key={index + itemText}>{itemText}</li>;
        };
        return <ul>{this.props.items.map(createItem)}</ul>;
    }
});
//clase for create the form and items of todo list
var FormApp = React.createClass({
    getInitialState: function()
    {
        return {
            text: ”,
            items: []
        };
    },
    onChange: function(e)
    {
        this.setState({text: e.target.value});
    },
    handleSubmit: function(e)
    {
        e.preventDefault();
        var nextItems = this.state.items.concat([this.state.text]);
        var nextText = ”;
        this.setState({items: nextItems, text: nextText});
    },
    render: function()
    {
        return (
            <div>
                <h3>React Todo List</h3>
                <TodoList items={this.state.items} />
                <form onSubmit={this.handleSubmit}>
                  <input type=“text” onChange={this.onChange} value={this.state.text} />
                  <button type=“submit”>Add</button>
                </form>
            </div>
        );
    }
});
React.render(<FormApp />, document.getElementById(“content”));

 

Filed Under: HTML5, JavaScript, React JS Tagged With: classes, Forms, javascript, REACTJS, todo list

Primary Sidebar

Categorías

  • Angular JS (10)
  • BackBone JS (6)
  • Ember JS (2)
  • Express JS (4)
  • EXTJS (1)
  • General (7)
  • GIT (3)
  • Grunt JS (2)
  • HTML5 (8)
  • JAVA (5)
  • JavaScript (14)
  • JQUERY (15)
  • JSON (1)
  • JSP (1)
  • Knockout JS (2)
  • LARAVEL (13)
  • Linux (2)
  • Mobile Angular UI (1)
  • Modulus.io (1)
  • MongoDB (5)
  • MySQL (3)
  • NodeJS (11)
  • PHP (1)
  • Polymer (3)
  • PostgreSQL (1)
  • Prism.JS (1)
  • PYTHON (10)
  • QOOXDOO (1)
  • React JS (7)
  • Redis (2)
  • Sin categoría (6)
  • SQL (1)
  • TWIG (4)
  • UnderScore (1)
  • Web Services. (2)
  • Wordpress (1)

Cloud Tags

Angular JS BackBone JS Ember JS Express JS EXTJS General GIT Grunt JS HTML5 JAVA JavaScript JQUERY JSON JSP Knockout JS LARAVEL Linux Mobile Angular UI Modulus.io MongoDB MySQL NodeJS PHP Polymer PostgreSQL Prism.JS PYTHON QOOXDOO React JS Redis Sin categoría SQL TWIG UnderScore Web Services. Wordpress

Copyright © 2023 · Genesis Sample Theme on Genesis Framework · WordPress · Log in