From d774a36057dcb46ea984e18c08401c288855e35a Mon Sep 17 00:00:00 2001 From: dudt Date: Wed, 25 Sep 2024 16:35:48 -0400 Subject: [PATCH] Final Solution --- src/App.jsx | 55 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 6478b09..904b530 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -2,24 +2,67 @@ import { useState } from "react"; import "./App.css"; function City(props) { - return
This is the City component
; + return ( +
+
{props.City}, {props.State}
+ +
+
    +
  • State:{props.State}
  • +
  • Location:({props.Lat},{props.Long})
  • +
  • Population (estimated): {props.EstimatedPopulation}
  • +
  • Total Wages:{props.TotalWages}
  • +
+
+
+ +) } -function ZipSearchField(props) { - return
This is the ZipSearchField component
; +function ZipSearchField({onSearch}) { + const[zipCode, setZipCode] = useState(""); + + const handleChange =(e) => { + setZipCode(e.target.value); + onSearch(e.target.value); + }; + + return() } function App() { + const[cities,setCities] = useState([]); + const[error,setError] = useState(""); + + const fetchCities = async(zipCode) =>{ + setError(""); + try{ + const response = await fetch(`https://ctp-zip-code-api.onrender.com/zip/${zipCode}`) + if(!response.ok) + { + throw new Error("No results found"); + } + const data = await response.json(); + setCities(data); + }catch(err){ + setCities([]); + } + }; return (

Zip Code Search

- +
- - + {cities.length > 0 ? ( + cities.map((city, index) => ( + // Spread city object as props + )) + ) : ( + No results found // Fallback message + )}