Course contentsShow
React
Lesson 4 of 2,3961. Why React ExistsFree lesson

Imperative vs Declarative UI Updates

The shift from telling the browser *how* to update (imperative) to describing *what* the UI should look like (declarative).

Imperative vs Declarative UI Updates

What you'll learn: How React changed UI development from step-by-step DOM instructions to describing what you want to see.

The Old Way: Imperative (Telling "How")

Before React, updating the UI was like giving someone turn-by-turn driving directions. You had to specify every single step:

"Find the button element. Change its text to 'Loading...'. Disable it. Find the status div. Clear its contents. Create a new paragraph. Set its text. Append it to the div."

This is imperative programming — you command the browser exactly how to change from state A to state B. With jQuery, you wrote code like:

$('#myButton').text('Loading...').prop('disabled', true);
$('#status').empty().append('<p>Processing...</p>');

Every state change required explicit DOM manipulation instructions.

The New Way: Declarative (Describing "What")

React introduced a declarative approach — like showing someone a photo of the destination instead of giving directions. You simply describe what the UI should look like for any given state:

Think of it as saying: "When loading is true, the button says 'Loading...' and is disabled. The status shows 'Processing...'."

You don't tell React how to update the DOM. You just declare what should appear, and React figures out the steps needed to make it happen.

Why This Matters

This is the fundamental shift that makes React powerful. Instead of writing fragile update logic that can break when you forget a step (the state-view synchronization problem), you describe the desired result. React handles all the messy "how" behind the scenes.

Key Takeaway: Imperative code tells the browser how to update step-by-step; declarative code describes what the UI should be, letting React figure out the updates automatically.