Answer the question
In order to leave comments, you need to log in
`
Why use render() in reactjs?
Initially it was like this
function App() {
gettingWeather = async() => {
const apiUrl = await
fetch(`http://api.openweathermap.org/data/2.5/weather?q=Kiev&appid=${apiKey}&units=metric`);
const data = await apiUrl.json();
console.log(data);
}
return (
<div className="App">
<Info />
<Weather />
<Form
weatherMethod={this.gettingWeather}
/>
</div>
);
}
class App extends React.Component {
gettingWeather = async() => {
const apiUrl = await
fetch(`http://api.openweathermap.org/data/2.5/weather?q=Kiev&appid=${apiKey}&units=metric`);
const data = await apiUrl.json();
console.log(data);
}
render() {
return (
<div className="App">
<Info />
<Weather />
<Form
weatherMethod={this.gettingWeather}
/>
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
in the first case, you have an error in the line
You are accessing the current function without linking it to the asynchronous method gettingWeather
And about render here is the dock
weatherMethod={this.gettingWeather}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question