From 0d4584e0488c1404f9e4f3faab8ad928cf3a6889 Mon Sep 17 00:00:00 2001 From: Temur662 Date: Fri, 4 Oct 2024 16:20:38 -0400 Subject: [PATCH] Finished --- src/App.jsx | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 6478b09..b037a13 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,25 +1,61 @@ import { useState } from "react"; import "./App.css"; -function City(props) { - return
This is the City component
; +function City(city) { + return ( +
+
+

{city.city.LocationText}

+
+
    +
  • State: {city.city.State}
  • +
  • Location: ({city.city.Lat}, {city.city.Long})
  • +
  • Population (estimated): {city.city.EstimatedPopulation}
  • +
  • Total Wages: {city.city.TotalWages}
  • +
+
+
+
+ ) } -function ZipSearchField(props) { - return
This is the ZipSearchField component
; +function ZipSearchField({ setCityData }) { + const fetchZipcodes = (zipcode) => { + fetch(`https://ctp-zip-code-api.onrender.com/zip/${zipcode}`) + .then((response) => response.json()) + .then((data) => setCityData(data)) + .catch(() => setCityData(null)) + } + const onChange = () => { + const zip = document.getElementById('zipcode') + fetchZipcodes(zip.value) + } + return ( +
+
+ + +
+
+ ) } function App() { + const [ cityData, setCityData ] = useState() + console.log(cityData) return (

Zip Code Search

- -
- - + +
+ { cityData && cityData.length > 0 ? cityData.map((city) => { + return ( + + ) + }) : <>}