diff --git a/src/App.jsx b/src/App.jsx index 6478b09..42d1fe9 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,25 +1,71 @@ -import { useState } from "react"; +import { useEffect, useState } from 'react'; import "./App.css"; -function City(props) { - return
This is the City component
; +function Location(props) { + console.log(props.State) + return
+
{props.LocationText}
+ +
; } -function ZipSearchField(props) { - return
This is the ZipSearchField component
; +function ZipSearchInput({setLocationData, displayMessage}) { + const [zipCode, setZipCode] = useState(''); + + useEffect(() => { + const retrieveData = async () => { + if (zipCode.length === 5) { + try { + const response = await fetch(`https://ctp-zip-code-api.onrender.com/zip/${zipCode}`) + const data = await response.json() + if (data) { + setLocationData(data) + displayMessage('') + } + } catch (error) { + displayMessage('Error fetching location data', error) + setLocationData([]) + } + } else { + displayMessage('No results found') + setLocationData([]) + } + } + retrieveData() + }, [zipCode, setLocationData, displayMessage]) + + return ( + <> + + + ); } function App() { + const [locationData, setLocationData] = useState([]); + const [alertMessage, displayMessage] = useState('No results found'); + return (

Zip Code Search

- + +
{alertMessage}
- - + {locationData.map((location) => { + console.log(location) + return + })}