Skip to main content
InterviewHubPRO
Section Overview
Q16

Question 16 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

32%
Vue.js & Composition API (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

Dependency Injection with `provide()` and `inject()`.

senior LevelMost AskedCode ExampleDependency InjectionSystem Design

In Simple Words: Passes state from an ancestor component down to deeply nested children without prop drilling:

typescript
// Ancestor.vue
import { provide, ref } from 'vue';
const theme = ref('dark');
provide('theme-key', theme);

// DeepChild.vue
import { inject } from 'vue';
const theme = inject('theme-key', 'light'); // with fallback