Skip to content

Instantly share code, notes, and snippets.

@hmmhmmhm
Created June 22, 2022 04:41
Show Gist options
  • Save hmmhmmhm/cbc10b5d307556c649b6d386ec3942c6 to your computer and use it in GitHub Desktop.
Save hmmhmmhm/cbc10b5d307556c649b6d386ec3942c6 to your computer and use it in GitHub Desktop.
Vue in React Component
import { useEffect, useRef } from 'react'
interface IComponentProps<T> {
// TODO
}
const template = `
<div></div>
`
export const VueWithReactComponent = <T,>(props: IComponentProps<T>) => {
const ref = useRef<HTMLDivElement>(null)
const render = async () => {
if (typeof window === 'undefined') return
const { createApp, ref: vueRef, onMounted } = window.Vue
createApp({
setup() {
const componentRef = vueRef(null)
onMounted(() => {
// TODO
})
return {
componentRef
}
}
}).mount(ref.current)
}
useEffect(() => {
render()
}, [])
return (
<div
ref={ref}
dangerouslySetInnerHTML={{
__html: template,
}}
></div>
)
}
export default VueWithReactComponent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment