Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 0.1 — What React Is and Why It Exists
React · Example 1 of 3

Plain JavaScript: you write every update yourself

Two places show the count, so every click needs two update instructions. Forget one and the page lies.

React is a JavaScript library for building user interfaces: you describe what the screen should look like for the current data, and React updates the real page for you whenever that data changes.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Add a Reset button to the React counter that sets the count back to 0.

02

Write a Battery usage that shows a battery at 25%. What colour is it?

Explain it without notes

01

What problem does React solve that plain DOM code makes hard?

02

Explain the difference between imperative and declarative UI code with an example.

03

What does "UI = f(state)" mean?

04

Is React a library or a framework? What's the difference?

Plain JavaScript: you write every update yourself

Preview

Press Run to see the page.

Console

Nothing logged yet.