Created
August 14, 2022 10:08
-
-
Save modos/42abe348f09fcc22b7460d59272fb279 to your computer and use it in GitHub Desktop.
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
import React, { useState } from "react"; | |
import Select from "./Select"; | |
import Input from "./Input"; | |
import { units } from "../units"; | |
function App() { | |
const [result, setResult] = useState(0); | |
const [input, setInput] = useState(0) | |
const [toValue, setToValue] = useState(1); | |
const [fromValue, setFromValue] = useState(1); | |
function onChangeInput(e) { | |
setInput(e.target.value); | |
} | |
function onChangeSelectTo(e) { | |
setToValue(e.target.value); | |
} | |
function onChangeSelectFrom(e) { | |
setFromValue(e.target.value); | |
} | |
function convert() { | |
setResult(input * toValue / fromValue); | |
} | |
return ( | |
<> | |
<div className="converter-form"> | |
<Input label="Amount" onChange={onChangeInput}/> | |
<div className="row"> | |
<Select label="From" items={units} onChange={onChangeSelectTo}/> | |
<Select label="To" items={units} onChange={onChangeSelectFrom}/> | |
<button onClick={convert}>Convert</button> | |
</div> | |
</div> | |
<div id="result"> | |
Result is: <span data-testid="result">{result}</span> | |
</div> | |
</> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment