Event
ReasonReact events map cleanly to ReactJS synthetic events. ReasonReact exposes a module called ReactEvent
to help you work with events.
ReactEvent module contains all event types as submodules, e.g. ReactEvent.Form
, ReactEvent.Mouse
, etc.
You can access their properties using the ReactEvent.{{EventName}}.{{property}}
method. For example, to access the target
property of a ReactEvent.Form.t
event, you would use ReactEvent.Form.target
.
Since target
is a JavaScript Object, those are typed as Js.t
. If you're accessing fields on an object, like event.target.value
, you'd use Melange's ##
object access FFI:
ReactEvent.Form.target(event)##value;
Or, equivalently, using the pipe first operator:
event->ReactEvent.Form.target##value;
More info in the inline docs.