Created
June 22, 2022 04:41
-
-
Save hmmhmmhm/cbc10b5d307556c649b6d386ec3942c6 to your computer and use it in GitHub Desktop.
Vue in React Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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