Skip to main content
InterviewHubPRO
Section Overview
Q48

Question 48 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

96%
Vue.js & Composition API (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Vue 3 Render Functions & JSX: When to Drop Down from Templates.

senior LevelCode ExampleComponentsSystem DesignVue & Nuxt

In Simple Words: Render functions use the h() function to programmatically create Virtual DOM nodes (VNodes). While templates are declarative and optimized, render functions provide full JavaScript flexibility for highly dynamic scenarios (e.g. dynamic heading tags h(props.tag, slots.default()) or building form schema renderers).

typescript
import { h, defineComponent } from 'vue';

export const DynamicHeading = defineComponent({
  props: {
    level: { type: Number, required: true },
    title: { type: String, required: true }
  },
  setup(props, { slots }) {
    // Generates <h1>, <h2>, etc. dynamically without 6 v-if branches in template
    return () => h(`h${props.level}`, { class: 'heading-style' }, slots.default ? slots.default() : props.title);
  }
});