import { FormEventHandler, useState } from "react"; function App() { const [password, setPassword] = useState(""); const [passwordLength, setPasswordLength] = useState(6); const [withNumbers, setWithNumbers] = useState(false); const generatePassword: FormEventHandler = (e) => { e.preventDefault(); fetch("http://localhost:8080/new", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ length: passwordLength, with_numbers: withNumbers, }), }) .then((res) => res.json()) .then(({ password }) => setPassword(password)) .catch((error) => console.error(error)); }; return (

Password Generator

New password: {password || "..."}
setPasswordLength(parseInt(e.target.value))} />
setWithNumbers(e.target.checked)} />
); } export default App;