Last active
August 29, 2015 14:17
-
-
Save fredchu/2745a3105ae80c7e2a53 to your computer and use it in GitHub Desktop.
React Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Pinkoi Dev Sharing ReactJS Demo</title> | |
</head> | |
<body> | |
<div id="wrap"></div> | |
<script src="https://fb.me/react-0.13.0.js"></script> | |
<script src="https://fb.me/JSXTransformer-0.13.0.js"></script> | |
<script type="text/jsx"> | |
var TodoList = React.createClass({ | |
getInitialState: function () { | |
return { | |
list: [ | |
'jQuery', | |
'ReactJS', | |
'AngularJS', | |
'Vue.js', | |
'Array.observe()' | |
] | |
}; | |
}, | |
addTodo: function (e){ | |
e.preventDefault(); | |
var todoCotent = React.findDOMNode(this.refs.todoCotent).value.trim(); | |
if (!todoCotent) { | |
return; | |
} | |
var list = this.state.list; | |
list.push(todoCotent); | |
this.setState({list: list}); | |
React.findDOMNode(this.refs.todoCotent).value = ''; | |
}, | |
render: function() { | |
var todos = this.state.list.map(function (todo) { | |
return ( | |
<li>{todo}</li> | |
); | |
}); | |
return ( | |
<div> | |
<h1>Todos count: <span>{this.state.list.length}</span></h1> | |
<ul> | |
{todos} | |
</ul> | |
<form action="" onSubmit={this.addTodo}> | |
<input type="text" ref="todoCotent" /> | |
<input type="submit" value="Add a Todo" /> | |
</form> | |
</div> | |
); | |
} | |
}); | |
React.render( | |
<TodoList />, | |
document.getElementById('wrap') | |
); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment