From afdc06151509a7439dd711fc135173545d040793 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 23 Jan 2024 13:17:38 +0100 Subject: [PATCH] Inital data fetch --- src/components/main/Root.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/main/Root.tsx b/src/components/main/Root.tsx index 9f520db..e759815 100644 --- a/src/components/main/Root.tsx +++ b/src/components/main/Root.tsx @@ -1,6 +1,23 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; + +const onWeatherFetch = async function (cb) { + const response = await fetch( + "http://api.weatherapi.com/v1/current.json?key=bfca7632f8dc4253859120435242301&q=Vienna&aqi=no", + ); + const data = await response.json(); + + cb(data); +}; const App: React.FC = () => { + const [data, setData] = useState(null); + + useEffect(() => { + onWeatherFetch(setData); + }, []); + + console.log(data); + return
Hello world
; };