I have a problem when I click my button.
This error only came up after I added
async (e) => {
e.preventDefault();
before adding that, it worked fine.
My App.js is:
import React from "react";
import Titles from "./components/Titles.js";
import Form from "./components/Form.js";
import Weather from "./components/Weather.js";
const API_KEY = "6726a7ca2675f6208f516878e6472f36";
class App extends React.Component {
getWeather = async (e) => {
e.preventDefault();
const api_call = await fetch(`api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=${API_KEY}`);
const data = await api_call.json();
console.log(data);
}
render() {
return (
<div>
<Titles />
<Form getWeather={this.getWeather}/>
<Weather />
</div>
);
}
}
export default App;
And my Form.js is:
import React from "react";
class Form extends React.Component {
render() {
return (
<form onSubmit={this.props.getWeather}>
<input type="text" name="city" placeholder="City..."/>
<input type="text" name="Country" placeholder="Country..."/>
<button>Get Weather</button>
</form>
);
}
};
export default Form;
All I'm trying to do is log the returned API data when the button is clicked. So I need to stop the page refreshing when the button is clicked.