--- title: Prefer Props and Emit Over Component Refs impact: MEDIUM impactDescription: Component refs create tight coupling and break component abstraction type: best-practice tags: [vue3, component-refs, props, emit, component-design, architecture] --- # Prefer Props and Emit Over Component Refs **Impact: MEDIUM** - Using template refs to access child component internals creates tight coupling between parent and child. This makes components harder to maintain, refactor, and reuse. Props and emit provide a cleaner contract-based API that preserves component encapsulation. Component refs should be reserved for imperative actions (focus, scroll, animations) that can't be expressed declaratively. ## Task Checklist - [ ] Use props for passing data down to children - [ ] Use emit for communicating events up to parents - [ ] Only use component refs for imperative DOM operations - [ ] If using refs, expose a minimal, documented API via defineExpose - [ ] Consider if the interaction can be expressed declaratively **Incorrect:** ```vue ``` ```vue ``` **Correct:** ```vue ``` ```vue ``` ## When Component Refs ARE Appropriate ```vue ``` ```vue ``` ## Summary | Use Case | Approach | |----------|----------| | Pass data to child | Props | | Child notifies parent | Emit events | | Two-way binding | v-model (props + emit) | | Focus, scroll, animate | Component ref with minimal expose | | Access child internal state | Refactor to use props/emit | ## Reference - [Vue.js Component Basics - Props](https://vuejs.org/guide/components/props.html) - [Vue.js Component Events](https://vuejs.org/guide/components/events.html) - [Vue.js Template Refs - Ref on Component](https://vuejs.org/guide/essentials/template-refs.html#ref-on-component)