Skip to content

Instantly share code, notes, and snippets.

@erudenko
Created April 25, 2025 05:07
Show Gist options
  • Select an option

  • Save erudenko/67a0e757ec6f7c59ebd2672234481d06 to your computer and use it in GitHub Desktop.

Select an option

Save erudenko/67a0e757ec6f7c59ebd2672234481d06 to your computer and use it in GitHub Desktop.
WeatherWidget example
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