Cannot use components as JSX root elements? #12837
Answered
by
pdsuwwz
ettersi
asked this question in
Help/Questions
-
This doesn't work as intended: <script setup lang="jsx">
import { ref } from 'vue';
import SomeComponent from './SomeComponent.vue';
import SomeOtherComponent from './SomeOtherComponent.vue';
const Jsx = ref(<SomeComponent />);
setTimeout(
() => {
console.log("Loading SomeOtherComponent");
Jsx.value = <SomeOtherComponent />;
},
2000
);
</script>
<template>
<div>
<Jsx />
</div>
</template> After the two-seconds timeout, I see the |
Beta Was this translation helpful? Give feedback.
Answered by
pdsuwwz
Feb 24, 2025
Replies: 1 comment
-
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> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ettersi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can try adding an arrow function as follows: Playground