Skip to content

Instantly share code, notes, and snippets.

@ncaq
Created September 4, 2019 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncaq/89a92ebac2363d72a692b3a94cf090ef to your computer and use it in GitHub Desktop.
Save ncaq/89a92ebac2363d72a692b3a94cf090ef to your computer and use it in GitHub Desktop.
Reasonによる単純todoアプリ
[@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