-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAppOptimized.res
35 lines (30 loc) · 874 Bytes
/
AppOptimized.res
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
@@config({no_export})
type state = {count: int}
type action =
| Increment
| Decrement
let initialState = {count: 0}
let reducer = (state, action) =>
switch action {
| Increment => {count: state.count + 1}
| Decrement => {count: state.count - 1}
}
module App = {
@react.component
let make = () => {
let (state, dispatch) = React.Uncurried.useReducer(reducer, initialState)
<main>
{React.string("Simple counter with reducer")}
<div>
<button onClick={_ => dispatch(.Decrement)}> {React.string("Decrement")} </button>
<span className="counter"> {state.count->string_of_int->React.string} </span>
<button onClick={_ => dispatch(.Increment)}> {React.string("Increment")} </button>
</div>
</main>
}
}
switch ReactDOM.querySelector("#root"){
| None => ()
| Some(e) =>
ReactDOM.render(<App/>,e)
}