-
Notifications
You must be signed in to change notification settings - Fork 7
/
react.js
36 lines (31 loc) · 961 Bytes
/
react.js
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
// This example uses ./list.js (an element created with base-element)
// in use with a React component: https://facebook.github.io/react/
var List = require('./list.js')
var React = require('react')
// Create a React component that wraps the List
var XList = React.createClass({
propTypes: {
items: React.PropTypes.arrayOf(React.propTypes.string)
},
componentDidMount: function () {
var list = new List(React.findDOMNode(this))
var data = this.props.items
list.render(data)
// When item clicked
list.addEventListener('clicked', function (item) {
window.alert('You clicked ' + item.innerHTML)
})
// When item added
list.addEventListener('added', function () {
data.push(String(Math.random() * 9999))
list.render(data)
})
},
render: function () {
return React.createElement('div')
}
})
React.render(
React.createElement(XList, { items: ['one', 'two', 'three'] }),
document.body
)