Vue3 Fundamentals · Reactivity

Destructure props reactively

reactive props destructure

Destructure props reactively

A child receives data through props. Writing props.count everywhere is noisy, so you reach for destructuring — but before Vue 3.5 that broke reactivity, and the destructured value froze at its first value.

Vue 3.5 makes destructuring props reactive. You destructure straight from defineProps, and each name stays connected to the prop:

<script setup>
const { count } = defineProps(['count']);
</script>

<template>
  <p>Count: {{ count }}</p>
</template>

count updates whenever the parent passes a new value. The compiler rewrites each destructured name into a getter, so you get the tidy syntax without losing the link.

This only works when you destructure defineProps directly. Copying the props object first — const props = defineProps(...) then const { count } = props — takes a plain snapshot, and the value stops updating.

The Test for this Lesson mounts your component with a count prop, changes it, and checks the label. Your component is exported from App.vue.

Challenge

The label shows the first prop value and never changes. Destructure the props reactively so the label follows them: export an App component from App.vue that takes a count prop and renders a paragraph labelled Count: <count>.

The Test mounts your component with count set to 1, changes the prop to 2, and expects the paragraph to read Count: 2. The starter destructures the props object, so the label stays Count: 1 and the Test fails.

App.vue
<script setup>
const props = defineProps(['count']);
const { count } = props;
</script>

<template>
  <p>Count: {{ count }}</p>
</template>

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.