I had this operational, now just blanking.. Just trying to search weatherBit
API by city name for data below are my onChange
and handleSearch
(from child onClick
) functions...
Below is my App.js component. thanks in advance.
constructor(props) {
super(props)
this.state = {
response: [],
inputVal: ""
}
}
handleSearch = () => {
getWeatherData(this.state.inputVal) //(call getWeatherData function from below)
}
componentDidMount() {
getWeatherData = inputVal => {
fetch(
"https://api.weatherbit.io/v2.0/current?city=Seattle,WA&key=168c5cb818e74abd926a9d65d285d48f"
)
.then(res => res.JSON())
.then(data => {
this.setState({ response: data })
console.log(data)
})
}
//handleChange from WeatherQuery input:
handleOnChange = e => {
this.setState({ inputVal: e.target.value })
}
}
render() {
return (
<div className="container">
<WeatherQuery
handleChange={this.state.handleChange}
handleSearch={this.state.handleSearch}
)
}
}
export default App
this is my input from child component->
<input
onChange={event =>
this.props.handleChange(event)}
name="text"
type="text"
placeholder=""
value={this.state.inputVal}
/>