Building a Weather Widget with React + MDX
MDX allows us to mix Markdown content with React components, so we can create interactive widgets inside blog posts.
In this post, we will:
- Build a
WeatherWidget
React component. - Fetch live weather data from the OpenWeather API.
- Display a weather icon depending on the conditions (sunny, cloudy, rain).
- Embed the component directly into our MDX post.
Live Example
Here’s the weather in London:
Loading weather...
You can change the city by passing a different city
prop:
<WeatherWidget city="New York" />
<WeatherWidget city="Tokyo" />