Skip to content

Commit 0897e02

Browse files
authored
Add handler_ for simple event handlers (#31)
1 parent a41fd55 commit 0897e02

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/React/Basic/Events.purs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ derive newtype instance categoryBuilder :: Category EventFn
6060
handler :: forall a. EventFn SyntheticEvent a -> (a -> Eff (react :: ReactFX) Unit) -> EventHandler
6161
handler (EventFn fn) cb = mkEffFn1 $ fn >>> cb
6262

63+
-- | Create an `EventHandler` which discards the `SyntheticEvent`.
64+
-- |
65+
-- | For example:
66+
-- |
67+
-- | ```purs
68+
-- | input { onChange: handler_ (setState \_ -> { value })
69+
-- | }
70+
-- | ```
71+
handler_ :: forall a. Eff (react :: ReactFX) Unit -> EventHandler
72+
handler_ = mkEffFn1 <<< const
73+
6374
class Merge (rl :: RowList) fns a r | rl -> fns, rl a -> r where
6475
mergeImpl :: RLProxy rl -> Record fns -> EventFn a (Record r)
6576

0 commit comments

Comments
 (0)