As a frontend project, antfu/reactivue has picked up 1.5k stars on GitHub (TypeScript). 🙊 Use Vue Composition API in React components
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
I love Vue Composition API and its reactivity system, but functional components in React are also sweet with Typescript. Instead of making a choice, why not to use them together?
Usage
Component Factory
import React from 'React'
import { defineComponent, ref, computed, onUnmounted } from 'reactivue'
interface Props {
value: number
}
const MyCounter = defineComponent(
// setup function in Vue
(props: Props) => {
const counter = ref(props.value)
const doubled = computed(() => counter.value * 2)
const inc = () => counter.value += 1
onUnmounted(() => console.log('Goodbye World'))
return { counter, doubled, inc }
},
// functional component in React
({ counter, doubled, inc }) => {
// you can still use other React hooks
return (
<div>
<div>{counter} x 2 = {doubled}</div>
<button onClick={inc}>Increase</button>
</div>
)
}
)
// use it as you normally would
render(<MyCounter value={10}>, el)
Hooks
You can use it as a hook as well.
The defineComponent factory is actually a sugar to and equivalent to the following code.
import React from 'React'
import { useSetup, ref, computed, onUnmounted } from 'reactivue'
interface Props {
value: number
}
function MyCounter(Props: Props) {
const state = useSetup(
(props: Props) => { // props is a reactive object in Vue
const counter = ref(props.value)
const doubled = computed(() => counter.value * 2)
const inc = () => counter.value += 1
onUnmounted(() => console.log('Goodbye World'))
return { counter, doubled, inc }
},
Props // pass React props to it
)
// state is a plain object just like React state
const { counter, doubled, inc } = state
return (
<div>
<div>{counter} x 2 = {doubled}</div>
<button onClick={inc}>Increase</button>
</div>
)
}
Hook Factory
To reuse the composition logics, createSetup is provided as a factory to create your own hooks.
To use reactivue in Preact apps, just replace reactivue import with reactivue/preact
import { h } from 'preact'
-import { defineComponent, ref, computed, onUnmounted } from 'reactivue'
+import { defineComponent, ref, computed, onUnmounted } from 'reactivue/preact'
Using Vue's Libraries
Yes, you can! Before you start, you need set alias in your build tool in order to redirect some apis from vue to reactivue or reactivue/preact if you are using it with Preact.
Installing Vue plugins are almost identical to Vue. Just simply create your root instance with createApp function and register your plugins as you do in Vue apps. You don't need to call app.mount. Your Vue plugins will be available in all your setup functions.
import { createApp } from 'reactivue'
import { createPinia } from 'pinia'
const app = createApp()
app.use(createPinia())
Note: If you are trying to use a library that calls app.component, app.directive or app.mixin in its install function, reactivue will skip these calls without any action and warn you about it.
Compatible Libraries
A list of libaries that have been tested to work with reactivue. Feel free to make PRs adding more.
pinia - 🍍 Automatically Typed, Modular and lightweight Store for Vue
VueUse - 🧰 Collection of Composition API utils for Vue 2 and 3
Villus - 🏎 A tiny and fast GraphQL client for Vue.js
APIs
Some tips and cavert compare to Vue's Composition API.
Reactivity
The reactivity system APIs are direct re-exported from @vue/reactivity, they should work the same as in Vue.
// the following two line are equivalent.
import { ref, reactive, computed } from 'reactivue'
import { ref, reactive, computed } from '@vue/reactivity'
Lifecycles
This library implemented the basic lifecycles to bound with React's lifecycles. For some lifecycles that don't have the React equivalent, they will be called somewhere near when they should be called (for example onMounted will be call right after onCreated).
For most of the time, you can use them like you would in Vue.
Extra APIs
defineComponent() - not the one you expected to see in Vue. Instead, it accepts a setup function and a render function that will return a React Functional Component.
useSetup() - the hook for resolve Composition API's setup, refer to the section above.
createSetup() - a factory to wrapper your logics into reusable custom hooks.
Limitations
getCurrentInstance() - returns the meta info for the internal states, NOT a Vue instance. It's exposed to allow you check if it's inside a instance scope.
No homepage URL was recorded for antfu/reactivue in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How active is development on antfu/reactivue?
The most recent commit recorded on antfu/reactivue was 2.4 years ago, based on the GitHub push timestamp. The repository has 37 forks — one of the better signals of community interest.
How many stars does antfu/reactivue have?
antfu/reactivue has 1.5k GitHub stars — refresh the page for the live number, or check github.com/antfu/reactivue. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is antfu/reactivue written in?
antfu/reactivue is written primarily in TypeScript. GitHub's language field is based on the largest share of bytes in the default branch.
What license does antfu/reactivue use?
antfu/reactivue is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
What topics is antfu/reactivue associated with?
GitHub's repository topics for antfu/reactivue: "react", "vue", "vue-composition-api", "vue-in-react". TopGit's editorial category is Frontend.
Where do I read more about antfu/reactivue?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/antfu/reactivue is the definitive source.
Read full README in the tab above.
Want a second opinion on reactivue?
Ask an AI that can read this page — one click and you get its take on reactivue.