-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathmain.js
48 lines (41 loc) · 1.05 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
const React = require('react')
const ReactDom = require('react-dom')
const Tags = require('../lib/ReactTags')
const suggestions = require('./countries')
class App extends React.Component {
constructor (props) {
super(props)
this.state = {
tags: [
{ id: 184, name: 'Thailand' },
{ id: 86, name: 'India' }
],
suggestions
}
}
handleDelete (i) {
const tags = this.state.tags.slice(0)
tags.splice(i, 1)
this.setState({ tags })
}
handleAddition (tag) {
const tags = [].concat(this.state.tags, tag)
this.setState({ tags })
}
render () {
return (
<div>
<Tags
delimiterChars={[',', ' ']}
tags={this.state.tags}
suggestions={this.state.suggestions}
handleDelete={this.handleDelete.bind(this)}
handleAddition={this.handleAddition.bind(this)} />
<hr />
<pre><code>{JSON.stringify(this.state.tags, null, 2)}</code></pre>
</div>
)
}
}
ReactDom.render(<App />, document.getElementById('app'))