1.0.8 • Published 10 months ago

react-vue-use-reactive v1.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

react-vue-use-reactive

Use Vue's reactivity system in React right now!

Useage:

npm install -S vue
npm install -S react-vue-use-reactive

Live Demo

Example: App.tsx

import { reactive } from "vue";
import { useReactive } from "react-vue-use-reactive";

interface IPerson {
  name: string;
  age: number;
}

let obj = reactive({
  data: {
    persons: [
      { name: "foo", age: 1 },
      { name: "bar", age: 2 },
    ],
  },
});

setTimeout(() => {
  console.log("[push] person ====================");
  obj.data.persons.push({ name: "qux", age: 3 });
}, 3000);

setTimeout(() => {
  console.log("[delete] person ====================");
  obj.data.persons.splice(0, 1);
}, 6000);

function Person({ person }: { person: IPerson }) {
  return useReactive(() => {
    return (
      <div>
        <div>{`${person.name}: ${person.age}`}</div>
        <button
          onClick={() => {
            person.age++;
          }}
        >{`Add [${person.name}] Age`}</button>
      </div>
    );
  });
}

function App() {
  return useReactive(() => {
    return (
      <div>
        {obj.data.persons.map((item, id) => (
          <Person key={id} person={item}></Person>
        ))}
      </div>
    );
  });
}

export default App;
1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago