-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (30 loc) · 824 Bytes
/
script.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
import { Component, createElement, button, div, text } from './lib/React'
import { render } from './lib/ReactDOM'
class A extends Component {
constructor(props, updater) {
super(props, updater)
this.state = { count: 0 }
}
render() {
return (
div({ className: this.state.count % 2 ? 'blue' : 'red' },
text(
{ body: `count: ${this.state.count}` }),
button(
{ onClick: e => this.setState({ count: this.state.count + 1 }),
className: this.state.count % 2 ? 'red' : 'blue'},
text(
{ body: 'click me' }),
),
createElement(B)
)
)
}
}
class B extends Component {
render() {
return div(null,
text({ body: 'Hello!' }))
}
}
render(div(null, createElement(A)), document.getElementById('root'))