@my-react/react-reactive
TypeScript icon, indicating that this package has built-in type declarations

0.3.8 • Public • Published

@my-react/react-reactive

this package provider a Vue like api for @my-react, you can use it to create reactive hook and component

import { reactive, createReactive, onMounted, onUnmounted } from "@my-react/react-reactive";

const useReactiveApi_Position = () => {
  const position = reactive({ x: 0, y: 0 });
  let id = null;
  const action = (e) => ((position.x = e.clientX), (position.y = e.clientY));
  onMounted(() => {
    window.addEventListener("mousemove", action);
  });

  onUnmounted(() => {
    window.removeEventListener("mousemove", action);
  });

  return position;
};

const Reactive1 = createReactive({
  setup(props, context) {
    const position = useReactiveApi_Position();
    const data = reactive({ a: 1 });
    const click = () => data.a++;

    return { data, click, position };
  },
});

const App = () => {
  return (
    <Reactive1 title="hello">
      {({ data, click, position, title }) => (
        <>
          <p>{data.a}</p>
          <button onClick={click}>click</button>
          <p>
            {position.x} {position.y}
          </p>
          {title}
        </>
      )}
    </Reactive1>
  );
};

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.3.812latest

Version History

VersionDownloads (Last 7 Days)Published
0.3.812
0.3.74
0.3.61
0.3.50
0.3.41
0.3.30
0.3.20
0.3.10
0.3.00
0.2.90
0.2.80
0.2.71
0.2.61
0.2.50
0.2.20
0.2.11
0.2.00
0.1.90
0.1.81
0.1.30
0.1.10
0.1.00
0.0.60
0.0.50
0.0.40
0.0.30

Package Sidebar

Install

npm i @my-react/react-reactive

Weekly Downloads

22

Version

0.3.8

License

MIT

Unpacked Size

232 kB

Total Files

41

Last publish

Collaborators

  • mrwang555