Vue Academy · Lesson

Dynamic Components with render Functions

Switching components by type, component resolution, keeping slots in render functions.

Lesson 3 of 413 steps

Dynamic Components with render Functions is a free Vue Academy lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 4 lessons in total.

Dynamic Components in Render Functions

Templates use <component :is="..."> to swap components at runtime. In a render function you achieve the same with the resolve helpers and h.

resolveComponent

resolveComponent looks up a globally or locally registered component by its registered name and returns it for use with h.

import { h, resolveComponent } from "vue";

export default {
  render() {
    const Btn = resolveComponent("MyButton");
    return h(Btn, null, () => "Click");
  }
};

resolveDynamicComponent

When the target may be a registered name, an HTML tag, or a component object, use resolveDynamicComponent. It handles all three cases.

import { h, resolveDynamicComponent } from "vue";

h(resolveDynamicComponent(props.type));

Driving the Type from Props

Pass the component name through a prop and resolve it each render. This is the render-function equivalent of :is.

export default {
  props: { type: String },
  render() {
    const Comp = resolveDynamicComponent(this.type);
    return h(Comp, { msg: "hi" });
  }
};

Forwarding Props

Spread incoming attrs onto the resolved component so the dynamic child receives everything the parent was given.

setup(props, { attrs }) {
  return () => h(
    resolveDynamicComponent(props.type),
    { ...attrs }
  );
}

Forwarding Slots

Slots reach a child through the third argument of h. Forward the parent's slots object directly so the dynamic component renders them.

setup(props, { slots }) {
  return () => h(
    resolveDynamicComponent(props.type),
    null,
    slots
  );
}

A Reusable Renderer

Combining attrs and slots forwarding produces a thin wrapper that renders any component by name while passing everything through.

setup(props, { attrs, slots }) {
  return () => h(
    resolveDynamicComponent(props.is),
    attrs,
    slots
  );
}

Dynamic Column Renderers

Data tables often let each column specify its own renderer component. Store the component name per column and resolve it for each cell.

const columns = [
  { field: "name", renderer: "TextCell" },
  { field: "price", renderer: "MoneyCell" }
];

Rendering Cells Dynamically

For each column, resolve its renderer and pass the cell value as a prop. One loop drives heterogeneous cell types.

render() {
  return h("tr", null,
    columns.map((col) =>
      h("td", null, [
        h(resolveDynamicComponent(col.renderer), {
          value: this.row[col.field]
        })
      ])
    )
  );
}

Falling Back to a Tag

If resolveDynamicComponent receives an unregistered name, it treats it as a native element string, so "div" renders a real div safely.

h(resolveDynamicComponent("div"), { class: "box" }, "fallback");

Why Use Render Functions Here

Render functions shine when the structure is computed - variable numbers of children, per-item component types, or logic that would need many nested template conditionals.

Quick Check

Which helper safely resolves a target that might be a component name OR a native HTML tag?

Recap

Use resolveComponent for registered names and resolveDynamicComponent when the target could also be an HTML tag or component object. Forward attrs as props and pass the slots object as the third h argument. This pattern powers dynamic table column renderers and flexible wrappers.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
42
Lessons
156

Frequently Asked Questions

Is the “Dynamic Components with render Functions” lesson free?

Yes — any 3 lessons of the Vue Academy learning path, including “Dynamic Components with render Functions”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 4 lessons in total.

What will I learn in “Dynamic Components with render Functions”?

Switching components by type, component resolution, keeping slots in render functions. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Vue Academy?

No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Dynamic Components with render Functions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Vue Academy lesson?

Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The h() Function Deep Dive
  2. JSX in Vue 3 with Vite
  3. Dynamic Components with render Functions
  4. Higher-Order Components (HOC) Pattern
← Back to Vue Academy