diff --git a/src/App.css b/src/App.css
index c7f4da8..f2f9b55 100644
--- a/src/App.css
+++ b/src/App.css
@@ -4,3 +4,7 @@
color: white;
text-align: center;
}
+
+li {
+ margin-left: 2em;
+}
diff --git a/src/App.jsx b/src/App.jsx
index 6478b09..56e892b 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,25 +1,66 @@
-import { useState } from "react";
+import {useState, useEffect} from "react";
import "./App.css";
function City(props) {
- return
This is the City component
;
+ return
+
+
+ - State: {props.city.State}
+ - Location: ({props.city.Lat}, {props.city.Long})
+ - Population (estimated): {props.city.EstimatedPopulation}
+ - Total Wages: {props.city.TotalWages}
+
+
;
}
function ZipSearchField(props) {
- return This is the ZipSearchField component
;
+ return (
+
+ Zip code:
+
+
+ )
}
function App() {
+ const [zip, setZip] = useState("");
+ const [data, setData] = useState([]);
+
+ const ZipSearchHandler = (e) => {
+ if (e.target.value.length !== 5 && e.target.value.match(/^[0-9]/)) {
+ setData([]);
+ }
+ if (e.target.value.length === 5 && e.target.value.match(/[0-9]/)) {
+ setZip(e.target.value);
+ }
+ }
+
+ const DataFetcher = async () => {
+ try {
+ const response = await fetch(`https://ctp-zip-code-api.onrender.com/zip/${zip}`);
+ const data = await response.json();
+ setData(data);
+ }
+ catch (error) {
+ console.error(error);
+ }
+ }
+
+ useEffect(() => {DataFetcher(zip)}, [zip]);
+
return (
Zip Code Search
-
+
-
-
+ {data.length > 0 ? (
+ data.map((city, index) => )
+ ) : (
+ No results found
+ )}