Created
June 29, 2019 03:48
-
-
Save horsfallnathan/c9f681f0562e0d63ce3ed6f176eebef2 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, useEffect } from "react"; | |
import "./App.css"; | |
import SVGFile from "./svgFile"; | |
function App() { | |
const [inputValue1, setInputValue1] = useState(""); | |
const [calculatedRate, setCalculatedRate] = useState(0); | |
const handleChange = e => { | |
e.preventDefault(); | |
setInputValue1(e.target.value); | |
}; | |
useEffect(() => { | |
const a = inputValue1 >= 100 ? 100 : inputValue1; | |
let rate = Math.floor((a / 100) * 10); | |
rate = isNaN(rate) ? 0 : rate; | |
setCalculatedRate(rate); | |
}, [inputValue1]); | |
return ( | |
<div className="App"> | |
<h1>How would you rate your SVG knowledge?</h1> | |
<h2>{`~ ${calculatedRate * 10}%`}</h2> | |
<input | |
type="number" | |
id="Score" | |
value={inputValue1} | |
onChange={handleChange} | |
/> | |
<label htmlFor="Score">Input some value 0 - 100%</label> | |
<div className="svgImage"> | |
<SVGFile active={calculatedRate} /> | |
</div> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment