-
Notifications
You must be signed in to change notification settings - Fork 0
/
code-states.js
60 lines (47 loc) · 1.07 KB
/
code-states.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
49
50
51
52
53
54
55
56
57
58
59
60
"use strict"
require("./node_modules/bootstrap/dist/css/bootstrap.min.css")
import React, { Component, PropTypes } from 'react'
import ReactDOM from 'react-dom'
export class ClickCounterButton extends Component {
constructor (props) {
super(props)
}
render () {
return <button onClick={this.props.handler}>Button</button>
}
}
export class Content extends Component {
constructor (props) {
super(props)
this.state = {}
this.click = this.click.bind(this)
}
componentDidMount () {
this.setState({myvar:17})
setInterval(() => {
this.setState({hash: Math.random()})
}, 5100)
}
getURL () {
return 'http://github.com'
}
click () {
this.setState( (previousState, currentProps) => {
return {myvar: previousState.myvar + 1}
})
}
render () {
return (
<div>
<h1>Name: {this.state.myvar}</h1>
<p>This value is random: {this.state.hash}</p>
<p>URL: {this.getURL()}</p>
<ClickCounterButton handler={this.click}/>
</div>
)
}
}
ReactDOM.render(
<Content />,
document.getElementById('content')
)