Vue · Junior · Question 38 of 75

How can a deeply nested component receive a value without passing props through every level?

// ancestor
provide("theme", theme);
// any descendant
const theme = inject("theme");

Explanation

provide/inject avoids prop drilling. If you provide a ref, the injected value stays reactive. For app-wide state, Pinia is usually a better fit.

Further reading

Problem with a question

Vue · Junior · question 38

Test yourself

Take the Vue · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz