Ah, sure! First, here are some imports required for the example below:
import Web.Event.Event (Event)
import Web.Event.Event as Event
import Web.UIEvent.MouseEvent (toEvent)
Ok, so the query might to look like this:
data Query a
= GoTo State a
| IsIn (State -> a)
| PreventDefault Event (Query a)
We’ll need a MonadEffect constraint for your component + a helper function like Thomas suggested here https://github.com/slamdata/purescript-halogen/issues/426#issuecomment-320390523:
header :: forall m. MonadEffect m => H.Component HH.HTML Query Unit Message m
header = ...
where
preventClick q = HE.onClick \e -> Just $ PreventDefault (toEvent e) $ H.action q
Let’s do the eval part first:
eval = case _ of
...
PreventDefault e q → do
H.liftEffect $ Event.preventDefault e
eval q
Finally, we’ll use the preventClick in the render function like this:
[ ...
, HH.a
[ HP.href "#href"
, preventClick (GoTo 1)
]
[ HH.text "smth" ]
, ...
]
Here is another example from my app that I’m currently working on: https://gist.github.com/vyorkin/6c837b722a03c2a230db0cbbfbcbb7b6