Repo of the Day
gloriasoft/veaury
Published: Jun 23, 2023
Open repository ↗Use React in Vue3 and Vue3 in React, And as perfect as possible!
Summary
Veaury is a JavaScript library that lets you render Vue 3 components inside React applications and React components inside Vue 3 applications through a small set of higher-order components. It is published on npm as veaury under the MIT license and includes support for shared context, cross-framework hooks, SSR setups like Next.js and Nuxt, and a "pure mode" that avoids adding wrapper elements.
What it is useful for
- Mixing Vue 3 and React in one app, which helps when a codebase already contains components from both ecosystems
- Incremental migration between the two frameworks without rewriting every screen at once
- Embedding third-party UI libraries on the other side, such as a React
antdcomponent inside a Vue project, or a Vueelement-uiorvuetifycomponent inside a React project
How engineers can use it
- Install with the commands documented in the README:
yarn add veauryornpm i veaury -S. - Wrap the component to be embedded. In a React file:
import { applyPureReactInVue } from 'veaury'and registerapplyPureReactInVue(MyReactComponent)as a Vue component. The reverse isapplyVueInReactorapplyPureVueInReactto wrap a.vueSFC and drop it into JSX. The README recommendsapplyPureReactInVueandapplyPureVueInReactfor their pure-mode behavior. - Configure the build pipeline. Vite users must install
@vitejs/plugin-react,@vitejs/plugin-vue, and@vitejs/plugin-vue-jsx, then replace the default plugins withveauryVitePluginsimported fromveaury/vite/index.js, passingtype: 'vue'ortype: 'react'. For Webpack,@vue/cli, andcreate-react-app, the README links to separatedev-project-vue3anddev-project-reactrepos for the full configurations; the exact Webpack files are not in the main README. - For
react-dom19 and above, the README requiresveaury@^2.6.0plus a one-time global call tosetVeauryOptions({ react: { createRoot } }), or rendering will fail. - Cross-framework state uses React's
Provider/useContextand Vue'sprovide/inject, and theuseInjectPropsFromWrapperoption exposes React hooks inside Vue and Vue setup hooks inside React. Events, slots, scoped slots, andv-modelare mapped with documented conventions, includingv-slots={...}for named slots, anode:slot prefix for React nodes, andv-model={[value, setter]}for two-way binding. - Documented limitation: with
applyPureReactInVueorapplyReactInVue, rapidly changing values can lag during two-way binding; the README providesinjectSyncUpdateForPureReactInVueto patch the affected component, and the TOC also flags a TypeScript JSX type conflict that arises when Vue and React are used in the same project.