Created
April 4, 2017 04:19
-
-
Save joefiorini/2863861ad5ae49ca8a6934aeabc5a632 to your computer and use it in GitHub Desktop.
My First ReasonML Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Echo = { | |
include ReactRe.Component.Stateful; | |
let name = "Echo"; | |
type props = unit; | |
type state = {message: option string}; | |
let getInitialState _ => {message: None}; | |
let handleChange _ event => { | |
let value = (ReactDOMRe.domElementToObj (ReactEventRe.Form.target event))##value; | |
Some {message: Some value} | |
}; | |
let render {state, updater} => { | |
let message = | |
switch state.message { | |
| None => "" | |
| Some str => str | |
}; | |
<section> | |
<input onChange=(updater handleChange) value=message /> | |
(ReactRe.stringToElement message) | |
</section> | |
}; | |
}; | |
include ReactRe.CreateComponent Echo; | |
let createElement = wrapProps (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment