-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReactApp.re
34 lines (31 loc) · 906 Bytes
/
ReactApp.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module App = {
[@react.component]
let make = () => {
let (name, setName) = React.useState(() => World.name);
<div>
{[
"Hello, " ++ name ++ "!"
]
->Belt.List.map(greeting => <h1 key={greeting}> greeting->React.string </h1>)
->Belt.List.toArray
->React.array}
<label style=(ReactDOM.Style.make(~paddingRight="5px", ()))>{React.string("Name:")}</label>
<input
type_="text"
value={name}
onChange={event => {
let newName = React.Event.Form.target(event)##value;
setName(_ => newName);
}}
placeholder="Enter a name"
/>
</div>
};
};
switch (ReactDOM.querySelector("#root")) {
| Some(element) =>
let root = ReactDOM.Client.createRoot(element);
ReactDOM.Client.render(root, <App />);
| None =>
Js.Console.error("Failed to start React: couldn't find the #root element")
};