Free

Weather App with React

A network request has four states, not two — and the race is the fifth problem.

  • React
  • Vite
  • REST API

About this project

Search an Indian city and see current conditions and a seven-day forecast. Data from Open-Meteo — no account, no API key, nothing to sign up for.

The idea it is built around is that a network request has four states, not two. Beginners write loading and success; the two they forget are error and empty, which are the ones users actually hit. Underneath those is a fifth problem: type "Del", then finish "Delhi" quickly, and two requests are in flight — if the first resolves last, the screen shows the wrong city and nothing looks broken. The app models the whole thing as one state value rather than three booleans, and explains why three booleans permit eight combinations of which five are nonsense. That is exactly where a spinner on top of an error message comes from.

Rather than describe the race, the app ships a Race Lab that runs it in front of you, with a switch to turn the AbortController cleanup off and a log showing the cancel firing or not firing. The React key demonstration works the same way: tick a row, reorder the list, and watch the tick follow its city or stay behind, depending on whether the key came from the data or from the index.

What you will learn

  • Model async work as one state that can only be idle, loading, success, error or empty
  • See why three booleans allow eight combinations of which five are nonsense
  • Cancel a superseded request with AbortController, and watch the race without it
  • Write an effect that cleans up after itself, and understand the dependency array
  • Use a key that comes from the data, and see exactly what an index key breaks

Before you start

  • JavaScript basics, and a little React — components, props and useState
  • Node 18 or newer, then one npm install

New to React? The free React course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.