I am using the purescript-react library to create an app. I am trying to handle an onChange event on an input element: input [ Props.onChange $ \evt -> do ... ] I want to access `evt.target.value` (as I would in Javascript). Here's what the types look like: type SyntheticInputEvent = SyntheticEvent_ (SyntheticUIEvent' ( SyntheticEvent' () )) foreign import data SyntheticEvent_ :: # Type -> Type type SyntheticUIEvent' r = (detail :: Number, view :: NativeAbstractView | r) type SyntheticEvent' r = (bubbles :: Boolean, target :: NativeEventTarget, ... | r) I have tried doing the following: input [ Props.onChange $ evt -> do let SyntheticEvent_ (SyntheticUIEvent' { detail: detail, view: view, target: target }) = evt ... ] But that doesn't work. Any suggestions?
Activity
ethul commentedon Nov 7, 2018
You should be able to pass the
evtright to thetargetfunctionpurescript-react/src/React/SyntheticEvent.purs
Lines 272 to 273 in e059deb
This would give you a
NativeEventTarget, which at the moment you can unsafe coerce to get thevalueproperty.Hope this helps.
natefaubion commentedon Nov 7, 2018
I think
NativeEventTargetis technically opaque, since it can vary by platform. I think it'd be worth providing conversions in react-dom though.Jwhiles commentedon Nov 19, 2018
@natefaubion
Would a correct implementation of this look similar to this?
purescript-react/src/React/SyntheticEvent.purs
Lines 359 to 360 in e059deb
I'm happy to make a PR adding it if so.