I am trying to do a fetch
request in react.js and I don't seem to be fetching anything. I feel as though it is a stupid mistake and I am not noticing it. Any help would be appreciated.
import React, {Component} from 'react';
import './App.css';
import TimeSearch from './TimeSearch.jsx';
import CurrentTime from './CurrentTime.jsx';
class App extends Component {
constructor(props) {
super(props);
this.state = {
list: []
};
}
handleFormSubmit(item) {
var url = 'https://api.aladhan.com/timingsByCity?city=' + item + '&country=US&method=2';
fetch(url)
.then(response => {
return response.json();
})
.then(json => {
this.setState({
Fajir: json.Fajir,
Sunrise: json.Sunrise,
Dhuhr: json.Dhuhr
});
});
}
render() {
return (
<div className=App>
<h1>Welcome to Prayer Times!</h1>
<h6>Search for times in any city in the United States</h6>
<TimeSearch
handleFormSubmit={item => {
this.handleFormSubmit(item);
}}
/>
<CurrentTime Fajir={this.state.Fajir} />
</div>
);
}
}
export default App;
// Time Search Component
import React, {Component} from 'react';
class TimeSearch extends Component {
render() {
return (
<ul>
<form onSubmit={e => this.handleFormSubmit(e)}>
<input type=text id=lookUp placeholder=Search by City ref=seachBox />
<button type=submit id=searchButtons>
{' '}
Search{' '}
</button>
</form>{' '}
</ul>
);
}
handleFormSubmit(e) {
e.preventDefault();
var item = this.refs.searchBox.value;
this.props.handleFormSubmit(item);
}
}
export default TimeSearch;
// Current Time Component
import React, {Component} from 'react';
class CurrentTime extends Component {
render() {
return (
<div id=time>
<h1 id=fajir> {this.props.Fajir} </h1>
</div>
);
}
}
export default CurrentTime;
Update
https://i.stack.imgur.com/YJx9T.png
Nothing shows up when I log the which is confusing me and I tried making an API request using Postman windows application and it works 100% fine so I have no clue what is going on now