Skip to content

How to use React component in vitepress #2183

Closed Answered by brc-dd
ChaconneLuo asked this question in Q&A
Discussion options

You must be logged in to vote
<div ref="el" />

<script setup>
import { createElement } from 'react'
import { createRoot } from 'react-dom/client'
import { ref, onMounted } from 'vue'
import FooBar from './FooBar'

const el = ref()
onMounted(() => {
  const root = createRoot(el.value)
  root.render(createElement(FooBar, {}, null))
})
</script>

https://stackblitz.com/edit/vite-dnqmyv

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@franmc01
Comment options

Answer selected by ChaconneLuo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ChaconneLuo
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants