import React, { useState } from "react"; const App = () => { const [wordOne, setWordOne] = useState(""); const [wordTwo, setWordTwo] = useState(""); const [message, setMessage] = useState(""); const onPressButton = () => { // Construct the URL with query parameters //const url = `https://abadesalex-emb-rep.hf.space/api/sum_of_lengths?word1=${wordOne}&word2=${wordTwo}`; const url = `http://localhost:8000/api/sum_of_lengths?word1=${wordOne}&word2=${wordTwo}`; fetch(url, { method: "GET", headers: { "Content-Type": "application/json", }, }) .then((response) => response.json()) .then((data) => { if (data.sum !== undefined) { setMessage(`Sum of lengths: ${data.sum}`); } else { setMessage("Error: Unexpected response"); } }) .catch((error) => { console.error("Error:", error); setMessage("Error: Failed to fetch data"); }); }; return (
setWordOne(e.target.value)} placeholder="First Word" /> setWordTwo(e.target.value)} placeholder="Second Word" />

{message}

); }; export default App;