diff --git a/src/App.css b/src/App.css
index c7f4da8..40c1097 100644
--- a/src/App.css
+++ b/src/App.css
@@ -4,3 +4,5 @@
color: white;
text-align: center;
}
+
+
\ No newline at end of file
diff --git a/src/App.jsx b/src/App.jsx
index 6478b09..72fffb8 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,25 +1,48 @@
import { useState } from "react";
import "./App.css";
+import City from "./City";
+import ZipSearchField from "./ZipSearchField";
-function City(props) {
- return
This is the City component
;
-}
-
-function ZipSearchField(props) {
- return This is the ZipSearchField component
;
-}
function App() {
+ const [cities, setCities] = useState([]);
+ const [error, setError] = useState(null);
+
+
+ const fetchCitiesByZip = (zip) => {
+ if (zip.length === 5) {
+ fetch(`https://ctp-zip-code-api.onrender.com/zip/${zip}`)
+ .then((response) => {
+ if (!response.ok) {
+ throw new Error("No results found for this ZIP code.");
+ }
+ return response.json();
+ })
+ .then((data) => {
+ setCities(data);
+ setError(null);
+ })
+ .catch((err) => {
+ setError(err.message);
+ setCities([]);
+ });
+ } else {
+ setCities([]);
+ }
+ };
+
return (
Zip Code Search
-
+
-
-
+ {error &&
{error}
}
+ {cities.length > 0
+ ? cities.map((cityData, index) =>
)
+ : !error &&
No city data available. Please enter a valid ZIP code.
}
diff --git a/src/City.jsx b/src/City.jsx
new file mode 100644
index 0000000..d978ccf
--- /dev/null
+++ b/src/City.jsx
@@ -0,0 +1,20 @@
+function City({ cityData }) {
+ return (
+
+
+
{cityData.City}
+
+
+
+ - State: {cityData.State}
+ - Location: ({cityData.Lat},{cityData.Long})
+ - Total Wages: {cityData.TotalWages}
+ - Population (Estimated): {cityData.EstimatedPopulation}
+
+
+
+ );
+ }
+
+ export default City;
+
\ No newline at end of file
diff --git a/src/ZipSearchField.jsx b/src/ZipSearchField.jsx
new file mode 100644
index 0000000..2c293ec
--- /dev/null
+++ b/src/ZipSearchField.jsx
@@ -0,0 +1,25 @@
+import { useState } from "react";
+function ZipSearchField({ onZipChange }) {
+ const [zip, setZip] = useState("");
+
+
+ const handleInputChange = (e) => {
+ const newZip = e.target.value;
+ setZip(newZip);
+ onZipChange(newZip);
+ };
+
+ return (
+
+
+
+
+ );
+ }
+ export default ZipSearchField;
\ No newline at end of file