-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
96 lines (85 loc) · 2.32 KB
/
main.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/prop-types@15.6.0/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const state = {eventCount: 0, username: ''}
function App() {
return (
<div>
<p>
There have been { state.eventCount } events
</p>
<p>
<button onClick={increment}>Click</button>
</p>
<p>You typed: {state.username}</p>
<p>
<input onChange={updateUsername} />
</p>
</div>
)
}
function increment() {
setState({ eventCount: state.eventCount + 1 })
}
function updateUsername(event) {
setState({ username: event.target.value })
}
function setState(newState) {
Object.assign(state, newState)
renderApp()
}
function renderApp() {
ReactDOM.render(
<App />,
document.getElementById('root')
)
}
renderApp()
</script>
<!-- <script type="text/babel">
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const Counter = ({ value, onIncrement, onDecrement }) => (
<div>
<h1>{value}</h1>
<button onClick={onIncrement}>+</button>
<button onClick={onDecrement}>-</button>
</div>
)
const { createStore } = Redux;
const store = createStore(counter);
const render = () => {
ReactDOM.render(
<Counter
value={store.getState()}
onIncrement={() => store.dispatch({ type: 'INCREMENT' })}
onDecrement={() => store.dispatch({ type: 'DECREMENT' })}
/>,
document.getElementById('root')
);
};
store.subscribe(render);
render();
</script> -->
</body>
</html>