diff --git a/src/components/fetch weather/weather-fetch.jsx b/src/components/fetch weather/weather-fetch.jsx new file mode 100644 index 0000000..f6a6522 --- /dev/null +++ b/src/components/fetch weather/weather-fetch.jsx @@ -0,0 +1,40 @@ +import React, { Component } from "react"; +import "./weather-fetch.scss"; + +class Forecast extends Component { + constructor(props) { + super(props); + this.state = { + weather: null, + }; + } + + async componentDidMount() { + const response = await fetch( + "https://api.openweathermap.org/data/2.5/weather?q=istanbul&appid=yourapikey" + ); + const json = await response.json(); + this.setState({ weather: json }); + } + + render() { + if (!this.state.weather) { + return
; + } + function kelvinToCelsius(kel) { + let celsius = kel - 273.15; + return celsius.toFixed(2); + } + + return ( +
+ + İstanbul Hava Durumu: {kelvinToCelsius(this.state.weather.main.temp)}°С +
+ ); + } +} +export default Forecast;