diff --git a/README.md b/README.md index 92067a2..0c39318 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# CITY search lab is finished, but github wouldn't allow me to do git push. I will submit again later + # Zip Code React Lab In this exercise, you will create two React apps: diff --git a/zip-search/src/App.js b/zip-search/src/App.js index 91e9361..83f801c 100644 --- a/zip-search/src/App.js +++ b/zip-search/src/App.js @@ -2,26 +2,74 @@ import React, { Component } from 'react'; import './App.css'; -function City(props) { - return (
This is the City component
); +function City( {data} ) { + return ( +
+ City Name: { data.City } +
+ State: { data.State } + +
+ ); } + + function ZipSearchField(props) { - return (
This is the ZipSearchField component
); + return ( + /* +
+ Zip Code: + +
+ */ +
+ props.handleChange(e)} /> +
+ ); } class App extends Component { + + state = { + zipCode: '', + cities: [], + } + + zipChange = (event) => { + this.setState({ zipCode: event.target.value }) + + if(event.target.value.length === 5){ + fetch('https://ctp-zip-api.herokuapp.com/zip/'+event.target.value) + .then(res => res.json()) + .then(cities => { + console.log(cities) + this.setState( { cities } ); + }) + .catch(err => { + this.setState({ cities:[] }) + }) + }else{ + this.setState({ cities:[] }) + } + } + render() { return (

Zip Code Search

- + this.zipChange(e) }/> +
Current Zip code is: { this.state.zipCode }
- - + { this.state.cities.length === 0 ?

No Result

: null } + { this.state.cities.map(city => ) } + +
);