forked from purescript-react/purescript-react-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.purs
More file actions
31 lines (23 loc) · 693 Bytes
/
Counter.purs
File metadata and controls
31 lines (23 loc) · 693 Bytes
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
module Counter where
import Prelude
import React.Basic (Component, JSX, StateUpdate(..), capture_, createComponent, make)
import React.Basic.DOM as R
component :: Component Props
component = createComponent "Counter"
type Props =
{ label :: String
}
data Action
= Increment
counter :: Props -> JSX
counter = make component { initialState, update, render }
where
initialState = { counter: 0 }
update self = case _ of
Increment ->
Update self.state { counter = self.state.counter + 1 }
render self =
R.button
{ onClick: capture_ self Increment
, children: [ R.text (self.props.label <> ": " <> show self.state.counter) ]
}