Use Symbol keys to avoid naming collisions between providers.
Details
Vue's provide/inject is a dependency injection mechanism scoped to the component tree. A provider makes a value available to all its descendants, regardless of depth. Unlike props, the intermediate components do not need to know about or forward the value.
Trade-offs:
Implicit dependencies — it is not obvious from a component's props what injected values it depends on
Debugging is harder — there is no props panel in DevTools for injected values (though Vue DevTools does show provide/inject)
Overuse leads to "spooky action at a distance" — changes in a provider affect distant descendants
When NOT to use:
When only one level of nesting exists — just pass a prop
For application-wide global state — use Pinia stores instead
When multiple providers might conflict — the closest ancestor's provide wins, which can be confusing
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: vue-provide-inject3description: Vue Provide / Inject4---5# Vue Provide / Inject67> Share data across a component tree without prop-drilling using provide/inject89## When to Use1011- A parent component needs to share data with deeply nested descendants12- You want to avoid passing props through intermediate components that do not use them13- Implementing theme, locale, or configuration providers at the app level1415## Instructions16171. In the ancestor component, call `provide(key, value)` inside `<script setup>`.182. In any descendant, call `const value = inject(key)` to receive the provided value.193. Use `InjectionKey<T>` for type-safe provide/inject in TypeScript.204. Provide reactive values (`ref` or `reactive`) so descendants receive live updates.215. Always provide a default value or document that `inject()` may return `undefined`.2223```typescript24// Parent — provides theme25import { provide, ref } from 'vue';26const theme = ref('light');27provide('theme', theme);2829// Deep child — injects theme30import { inject } from 'vue';31const theme = inject('theme', ref('light'));32```33346. Use Symbol keys to avoid naming collisions between providers.3536## Details3738Vue's `provide`/`inject` is a dependency injection mechanism scoped to the component tree. A provider makes a value available to all its descendants, regardless of depth. Unlike props, the intermediate components do not need to know about or forward the value.3940**Trade-offs:**4142- Implicit dependencies — it is not obvious from a component's props what injected values it depends on43- Debugging is harder — there is no props panel in DevTools for injected values (though Vue DevTools does show provide/inject)44- Overuse leads to "spooky action at a distance" — changes in a provider affect distant descendants4546**When NOT to use:**4748- When only one level of nesting exists — just pass a prop49- For application-wide global state — use Pinia stores instead50- When multiple providers might conflict — the closest ancestor's provide wins, which can be confusing5152## Source5354https://patterns.dev/vue/provide-inject5556## Process57581. Read the instructions and examples in this document.592. Apply the patterns to your implementation, adapting to your specific context.603. Verify your implementation against the details and edge cases listed above.6162## Harness Integration6364- **Type:** knowledge — this skill is a reference document, not a procedural workflow.65- **No tools or state** — consumed as context by other skills and agents.6667## Success Criteria6869- The patterns described in this document are applied correctly in the implementation.70- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/vue-provide-inject in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Vue Provide / Inject It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.