Search code examples
vue.jsvuejs3instanceof

How to check if an object is a Vue component in Vue3?


With vue 2 I could simply just

import Vue from "vue"

and then do the following

if (!(myComponent instanceof Vue)) return

Is there a way to do it in Vue3?


Solution

  • It is not a very elegant solution but you can check if it has a render function.

    if (!(myComponent && typeof myComponent.render  === 'function')) return