reasonml-old / reason-react-example

Examples for ReasonReact
649 stars 116 forks source link

ReasonJs.Dom.HtmlElement.value (ReactEventRe.Form.target event) #11

Open chenglou opened 7 years ago

chenglou commented 7 years ago

@glennsl (since discord is down again. Also, I'm on freenode #reasonml)

Assuming ReactEventRe.Form.target event returns ReasonJs.Dom.element or ReasonJs.Dom.eventTarget, what reason-js function do I use to get the equivalent of myEvent.value? How would it work without unsafe cast to whatever type here?

glennsl commented 7 years ago

Element has asHtmlElement and HtmlElement has value.

So if it returns an element:

event
|> ReacEventRe.Form.target
|> Element.asHtmlElement
|> Option.unwrapUnsafely
|> HtmlElement.value

Pretty smooth, huh :D

I'm on my way to bed. Talk to you tomorrow.

glennsl commented 7 years ago

If it returns an eventTarget you're screwed. Unsafe way is only way. C'est la vie