Performance: Provide and inject for deep passing
MEDIUM IMPACT
This affects how data is passed deeply through component trees without prop drilling, impacting rendering and reactivity performance.
const Parent = { provide() { return { value: this.value } }, data() { return { value: 0 } }, template: `<Child1 />` } const Child1 = { inject: ['value'], template: `<Child2 />` } const Child2 = { inject: ['value'], template: `<Child3 />` } const Child3 = { inject: ['value'], template: `<div>{{ value }}</div>` }
const Parent = { template: `<Child1 :value=\"value\" />`, data() { return { value: 0 } } } const Child1 = { props: ['value'], template: `<Child2 :value=\"value\" />` } const Child2 = { props: ['value'], template: `<Child3 :value=\"value\" />` } const Child3 = { props: ['value'], template: `<div>{{ value }}</div>` }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Prop drilling through many components | Many prop updates | Multiple reflows | Higher paint cost | [X] Bad |
| Provide/inject for deep passing | Single reactive source | Minimal reflows | Lower paint cost | [OK] Good |