blob: 2ae5726f69a45ad0b4b1a29c7ad162a87adbcfb6 [file] [log] [blame]
swissChiliab615d82024-03-08 17:15:13 -05001const React = require("preact");
2const {useState} = require('preact/hooks');
3
4export const UnitsApp = () => {
5 const [hist, setHist] = useState([]);
6 const [query, setQuery] = useState("");
7 const [to, setTo] = useState("");
8
9 function doConversion(e) {
10 e.preventDefault();
11 console.log("conversion");
12 setQuery('');
13 setTo('');
14
15 convert(query, to).then(res => {
16 setHist([...hist, query + " -> " + to + " " + res]);
17 })
18 }
19
20 return (
21 <div>
22 <form class="query-row" onSubmit={doConversion}>
23 <input
24 type="text"
25 id="query"
26 value={query}
27 placeholder="From"
28 onChange={(val) => setQuery(val.target.value)}
29 ></input>
30 <input
31 type="text"
32 id="to"
33 value={to}
34 placeholder="To"
35 onChange={(val) => setTo(val.target.value)}
36 ></input>
37
38 <input type="submit"></input>
39 </form>
40
41 <ul>
42 {hist.map((entry) => (
43 <li>{entry}</li>
44 ))}
45 </ul>
46 </div>
47 );
48};