Skip to content

Cannot use components as JSX root elements? #12837

Answered by pdsuwwz
ettersi asked this question in Help/Questions
Discussion options

You must be logged in to vote

You can try adding an arrow function as follows: Playground

<script setup lang="jsx">
import { ref } from 'vue';
import SomeComponent from './SomeComponent.vue';
import SomeOtherComponent from './SomeOtherComponent.vue';

- const Jsx = ref(<SomeComponent />);
+ const Jsx = ref(() => <SomeComponent />);
setTimeout(
  () => {
    console.log("Loading SomeOtherComponent");
-    Jsx.value = <SomeOtherComponent />;
+    Jsx.value = () => <SomeOtherComponent />;
  }, 
  2000
);
</script>

<template>
  <div>
    <Jsx />
  </div>
</template>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ettersi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants