0.1.7 • Published 3 years ago

@hyrious/use-reactive v0.1.7

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

useReactive

Use vue's reactivity api in react.

Usage

import { useReactive } from "@hyrious/use-reactive";
function Counter() {
  const state = useReactive({ count: 0 });
  return <button onClick={() => state.count++}>{state.count}</button>;
}

How it works?

Vue's reactivity api does the trick:

import { reactive, watchEffect } from "vue";
const state = reactive({ count: 0 });
watchEffect(() => {
  console.log(state.count);
  // accessing "state.count" triggers a proxy's get handler.
  // vue depends on the proxy to track it, so the next time
  // state.count changes, watchEffect will run again.

  // if we do nothing here, watchEffect will loop run until
  // it find some deps. that's it.
});

License

MIT @ hyrious

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago