Created
September 4, 2019 03:13
-
-
Save ncaq/89a92ebac2363d72a692b3a94cf090ef to your computer and use it in GitHub Desktop.
Reasonによる単純todoアプリ
This file contains hidden or 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
[@react.component] | |
let make = () => { | |
let (todos, setTodos) = React.useState(() => []); | |
let (inputCurrent, setInputCurrent) = React.useState(() => ""); | |
<div> | |
<ol> | |
{ | |
List.map(todo => <li> {React.string(todo)} </li>, todos) | |
|> Array.of_list | |
|> React.array | |
} | |
</ol> | |
<form | |
onSubmit={ | |
event => { | |
ReactEvent.Form.preventDefault(event); | |
setTodos(_ => [inputCurrent, ...todos]); | |
setInputCurrent(_ => ""); | |
} | |
}> | |
<input | |
onChange={ | |
event => setInputCurrent(event->ReactEvent.Form.target##value) | |
} | |
value=inputCurrent | |
/> | |
<button /> | |
</form> | |
</div>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment