0.3.0 • Published 4 months ago

@my-react/react-reactive v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@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>
  );
};
0.3.0

4 months ago

0.2.9

4 months ago

0.2.8

5 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.2.7

6 months ago

0.2.6

6 months ago

0.2.2

9 months ago

0.2.5

8 months ago

0.1.9

11 months ago

0.1.0

1 year ago

0.1.1

1 year ago

0.1.8

1 year ago

0.0.5

1 year ago

0.1.3

1 year ago

0.0.4

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago