0Pricing
Vue Academy · Lesson

Dynamic Components with render Functions

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

Dynamic Components with render Functions is a free Vue Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Frequently asked questions

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

Yes — the full text of “Dynamic Components with render Functions” is free to read here on the web, and the Vue Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vue Academy course, upgrade to CoddyKit PRO.

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; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

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