Created
April 25, 2025 05:07
-
-
Save erudenko/67a0e757ec6f7c59ebd2672234481d06 to your computer and use it in GitHub Desktop.
WeatherWidget example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState } from 'react'; | |
| export const WeatherWidget = ({ city }: { city: string }) => { | |
| const [temp, setTemp] = useState<number | null>(null); | |
| fetch(`/api/weather?city=${city}`) | |
| .then(r => r.json()) | |
| .then(data => setTemp(data.temp)); | |
| if (temp === null) return <p>Loading…</p>; | |
| return <p>{city}: {temp}°C</p>; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment