Skip to content
Learn Netverks

Lesson

Step 12/36 33% through track

ref-reactive

ref and reactive

Last reviewed May 28, 2026 Content v20260528
Track mode
client_vue
Means
In-browser Vue TS
Reading
~2 min
Level
beginner

This lesson

This lesson teaches ref and reactive: the concepts, APIs, and habits you need before advancing in Vue.

Vue’s reactivity system tracks refs and reactive objects—mutating the wrong shape breaks updates silently.

You will apply ref and reactive in contexts like: Greenfield SPAs, dashboards, design systems, and full-stack apps that pair Vue with PHP or Node APIs.

Write TypeScript, click Run—Vue 3 loads from CDN with the template compiler, mountApp shows UI in #app, and printOutput feeds the terminal.

When you can explain the previous lesson's ideas without copying starter code.

Vue 3’s reactivity tracks data changes and updates the UI automatically. ref wraps any value (especially primitives); reactive makes objects deeply reactive.

ref basics

const count = ref(0);
count.value += 1; // .value in script
// {{ count }} in template — auto-unwrapped

In setup() and composables you read/write .value. Templates unwrap refs for you—no .value in mustaches.

reactive objects

const state = reactive({ count: 0, label: 'Draft' });
state.count += 1; // no .value for properties

Use reactive for object-shaped state; use ref for primitives or when you want to replace the whole value. Avoid destructuring reactive objects without toRefs—you lose reactivity.

Important interview questions and answers

  1. Q: ref vs reactive?
    A: ref works for any value with .value; reactive proxies plain objects. Prefer ref for primitives and when reassigning whole values.
  2. Q: Why .value in script but not template?
    A: Templates compile to unwrap refs automatically; script runs plain JavaScript.

Self-check

  1. What triggers a re-render when you mutate a ref?
  2. Why can destructuring reactive break updates?

Challenge

Click counter

  1. Click the button three times.
  2. Change the increment to add 2 per click.

Done when: the count increases by 2 on each click.

Tip: Use ref for primitives and reassignable values; use reactive for object-shaped state you mutate in place.

Interview prep

ref vs reactive?

ref wraps any value and uses .value in script; reactive makes object properties deeply reactive—prefer ref for primitives and reassignments.

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

  • ref vs reactive object?
  • Primitive in reactive()?

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