Performance: Higher-order components concept
MEDIUM IMPACT
This concept affects rendering speed and responsiveness by adding extra component layers in the Vue component tree.
const useLogger = (props) => { watchEffect(() => { console.log('Rendering component with props:', props); }); }; const Button = defineComponent({ props: { label: String }, setup(props) { useLogger(props); return () => h('button', null, props.label); } }); // Usage in template // <Button label="Click me" />
const withLogger = (WrappedComponent) => { return { props: WrappedComponent.props, setup(props, { slots }) { console.log('Rendering component with props:', props); return () => h(WrappedComponent, props, slots.default ? slots.default() : undefined); } }; }; const EnhancedButton = withLogger(Button); // Usage in template // <EnhancedButton label="Click me" />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| HOC wrapping base component | Increases component nodes by 1 per use | Triggers reactive updates on wrapper and base | Slightly higher due to deeper tree | [!] OK |
| Composable function inside component | No extra component nodes | Reactive updates only on base component | Lower paint cost due to simpler tree | [OK] Good |