Bird
Raised Fist0
Vueframework~20 mins

Props drilling problem in Vue - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Props Drilling Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What will be displayed by the deepest child component?

Consider a Vue 3 app where a prop is passed through multiple nested components. What text will the deepest child component render?

Vue
/* Parent.vue */
<template>
  <ChildA :message="parentMessage" />
</template>
<script setup>
const parentMessage = 'Hello from Parent'
</script>

/* ChildA.vue */
<template>
  <ChildB :message="message" />
</template>
<script setup>
const props = defineProps({ message: String })
const message = props.message
</script>

/* ChildB.vue */
<template>
  <ChildC :message="message" />
</template>
<script setup>
const props = defineProps({ message: String })
const message = props.message
</script>

/* ChildC.vue */
<template>
  <p>{{ message }}</p>
</template>
<script setup>
const props = defineProps({ message: String })
const message = props.message
</script>
AHello from Parent
BError: message is not defined
Cundefined
DEmpty paragraph with no text
Attempts:
2 left
💡 Hint

Trace how the message prop is passed down through each component.

❓ state_output
intermediate
2:00remaining
What is the value of the prop in the grandchild after update?

In this Vue 3 example, the parent updates the prop value after 1 second. What will the grandchild component display after the update?

Vue
<template>
  <ChildA :text="parentText" />
</template>
<script setup>
import { ref, onMounted } from 'vue'
const parentText = ref('Initial')
onMounted(() => {
  setTimeout(() => {
    parentText.value = 'Updated'
  }, 1000)
})
</script>

<!-- ChildA.vue -->
<template>
  <ChildB :text="text" />
</template>
<script setup>
const props = defineProps({ text: String })
const text = props.text
</script>

<!-- ChildB.vue -->
<template>
  <p>{{ text }}</p>
</template>
<script setup>
const props = defineProps({ text: String })
const text = props.text
</script>
AInitial, then changes to Updated after 1 second
BAlways shows Initial, no change
CAlways shows Updated immediately
DThrows an error after 1 second
Attempts:
2 left
💡 Hint

Consider how Vue's reactivity works with props and refs.

🔧 Debug
advanced
2:00remaining
Why does the child component not receive the prop value?

Given this Vue 3 code, the child component shows an empty paragraph instead of the expected prop value. What is the cause?

Vue
<template>
  <Child :msg="message" />
</template>
<script setup>
const message = 'Hello'
</script>

<!-- Child.vue -->
<template>
  <p>{{ msg }}</p>
</template>
<script setup>
const props = defineProps({ msg: String })
const msg = props.msg
</script>
AMissing import of Child component in parent
BTemplate syntax error in child component
CProp name mismatch: parent passes 'msg' but child expects 'message'
DUsing <script setup> disables props
Attempts:
2 left
💡 Hint

Check the prop names used in parent and child components.

🧠 Conceptual
advanced
2:00remaining
What is a main drawback of props drilling in Vue apps?

Props drilling means passing props through many nested components that do not use them directly. What is a key problem caused by this pattern?

AIt causes Vue to throw runtime errors
BIt makes components tightly coupled and harder to maintain
CIt disables reactivity in child components
DIt prevents components from rendering
Attempts:
2 left
💡 Hint

Think about how passing props through many layers affects code clarity and maintenance.

📝 Syntax
expert
3:00remaining
Which option correctly avoids props drilling using Vue 3 features?

You want to share data deeply without passing props through many components. Which code snippet correctly uses Vue 3's provide/inject to achieve this?

Vue
/* Parent.vue */
<template>
  <ChildA />
</template>
<script setup>
import { provide, ref } from 'vue'
const sharedData = ref('Shared info')
provide('sharedKey', sharedData)
</script>

/* ChildC.vue */
<template>
  <p>{{ sharedData.value }}</p>
</template>
<script setup>
import { inject } from 'vue'
const sharedData = inject('sharedKey')
</script>
AParent uses provide inside setup but does not import provide
BParent uses provide with a ref; Child uses inject but accesses sharedData without .value
CParent uses provide with a plain string; Child uses inject expecting a ref
DParent uses provide with a ref; Child uses inject and accesses the ref value directly
Attempts:
2 left
💡 Hint

Remember that ref values need to be accessed with .value in Vue 3.

Practice

(1/5)
1. What is props drilling in Vue?
easy
A. Using Vuex store to manage state globally
B. Passing props through many nested components to reach a child
C. Directly modifying props inside a child component
D. Using props only in the root component

Solution

  1. Step 1: Understand props usage in Vue

    Props are used to pass data from parent to child components.
  2. Step 2: Define props drilling

    Props drilling happens when you pass props through many layers of components just to reach a deeply nested child.
  3. Final Answer:

    Passing props through many nested components to reach a child -> Option B
  4. Quick Check:

    Props drilling = Passing props through many layers [OK]
Hint: Props drilling means many layers pass props down [OK]
Common Mistakes:
  • Thinking props drilling means using props only at root
  • Confusing props drilling with modifying props in child
  • Mixing props drilling with global state management
2. Which of the following is the correct way to pass a prop named title from a parent to a child component in Vue?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Recognize Vue prop binding syntax

    Props can be passed using shorthand : or full v-bind: syntax.
  2. Step 2: Compare options

    uses shorthand :, uses v-bind:. Both correctly bind the variable parentTitle as a prop.
  3. Final Answer:

    Both A and C -> Option A
  4. Quick Check:

    Use : or v-bind: for dynamic props [OK]
Hint: Use : or v-bind: to pass dynamic props [OK]
Common Mistakes:
  • Passing prop as plain string without binding
  • Confusing attribute with prop binding
  • Using incorrect syntax like
3. Given this component structure:
App -> Parent -> Child
and App passes a prop message to Parent, which passes it to Child. What will Child display if message is "Hello"?
<template>
  <div>{{ message }}</div>
</template>

<script setup>
defineProps(['message'])
</script>
medium
A. Hello
B. undefined
C. Error: message not defined
D. Empty string

Solution

  1. Step 1: Trace prop passing

    App passes message="Hello" to Parent, Parent passes it to Child as prop.
  2. Step 2: Child uses message prop correctly

    Child receives message prop and displays it inside the div.
  3. Final Answer:

    Hello -> Option A
  4. Quick Check:

    Prop passed down correctly = Hello [OK]
Hint: If prop passed correctly, child shows its value [OK]
Common Mistakes:
  • Forgetting to pass prop from Parent to Child
  • Not defining props in Child component
  • Expecting prop to be reactive without passing
4. In a Vue app, you pass a prop user from App to Parent and then to Child. You get an error: Property 'user' is not defined in Child. What is the likely cause?
medium
A. All of the above
B. Parent component did not pass user prop to Child
C. Child component did not declare user in defineProps
D. App did not pass user prop to Parent

Solution

  1. Step 1: Analyze the error message

    The error Property 'user' is not defined occurs when accessing a prop in the template without declaring it in defineProps in the Child.
  2. Step 2: Distinguish from other issues

    If declared but not passed from Parent or App, the prop would be undefined, not trigger this specific error.
  3. Final Answer:

    Child component did not declare user in defineProps -> Option C
  4. Quick Check:

    'Property not defined' = missing defineProps declaration [OK]
Hint: 'Property not defined' means missing defineProps in child [OK]
Common Mistakes:
  • Assuming props auto-pass without explicit binding
  • Not declaring props in child component
  • Ignoring error messages about undefined props
5. You want to avoid props drilling for a deeply nested component needing user data. Which Vue feature helps reduce props drilling?
hard
A. Using multiple emits to send data back up
B. Passing props through every intermediate component
C. Using local component state only
D. Using provide/inject to share data between ancestor and descendant

Solution

  1. Step 1: Understand props drilling problem

    Passing props through many layers is tedious and hard to maintain.
  2. Step 2: Identify Vue feature to avoid drilling

    Vue's provide/inject allows ancestor components to share data directly with descendants without passing props through every layer.
  3. Final Answer:

    Using provide/inject to share data between ancestor and descendant -> Option D
  4. Quick Check:

    Provide/inject reduces props drilling [OK]
Hint: Use provide/inject to skip intermediate props [OK]
Common Mistakes:
  • Thinking local state shares data globally
  • Using emits to send data down instead of up
  • Passing props through every layer instead of provide/inject
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard