Skip to content
Learn Netverks

Lesson

Step 3/36 8% through track

declarative-ui

Declarative UI

Last reviewed May 28, 2026 Content v20260528
Track mode
client_react
Means
In-browser React TSX
Reading
~2 min
Level
beginner

This lesson

This lesson teaches Declarative UI: the concepts, APIs, and habits you need before advancing in React.

Declarative UI is why teams adopt React—describe what should be on screen, not every DOM mutation step.

You will apply Declarative UI in contexts like: SPAs, dashboards, design-system-driven products, and React Native mobile apps.

Write TypeScript/TSX, click Run in browser—React 18 loads from CDN, JSX compiles in the tab, UI renders in the preview root, and printOutput feeds the terminal.

At the start of the track—complete before JSX-heavy lessons that assume you understand the playground.

Declarative UI means you describe the desired output; the library figures out how to update the DOM. Imperative UI means you spell out each step: create node, set attribute, append child, replace text.

Imperative vs declarative (conceptual)

// Imperative (vanilla)
const el = document.createElement('p');
el.textContent = 'Hello, ' + name;
container.appendChild(el);

// Declarative (React idea)
// return <p>Hello, {name}</p>;

When name changes in React, you re-run the component function with new state; React patches only what changed. You do not manually remove and recreate the paragraph.

UI as a function of state

A useful mental model: UI = f(state). Given the same state, you get the same description. That predictability makes debugging and testing easier than scattered DOM mutations.

Important interview questions and answers

  1. Q: What does declarative mean in React?
    A: You declare what the UI should look like for current props/state; React handles DOM updates.
  2. Q: Can React be used imperatively?
    A: Rarely via refs for focus or third-party widgets, but the default pattern is declarative components.

Self-check

  1. Rewrite “toggle a CSS class on click” in declarative terms (what state drives the class?).
  2. Why is UI = f(state) easier to reason about than ad-hoc DOM edits?

Interview prep

Declarative vs imperative UI?

Describe UI as a function of state; React patches the DOM when state changes instead of hand-writing every DOM step in large apps.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Declarative example from this lesson?
  • Imperative step you avoided?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump