From bb7a5cf379fd32faf4b47c52a7f2f0f1b7031082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C4=B0pek?= <69052962+yusufipk@users.noreply.github.com> Date: Fri, 22 Jan 2021 21:27:00 +0300 Subject: [PATCH] removed api key :D --- .../fetch weather/weather-fetch.jsx | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/components/fetch weather/weather-fetch.jsx 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 ( +