0.3.3 • Published 9 months ago
@my-react/react-reactive v0.3.3
@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.3
9 months ago
0.3.2
10 months ago
0.3.1
1 year ago
0.3.0
1 year ago
0.2.9
1 year ago
0.2.8
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.2.7
2 years ago
0.2.6
2 years ago
0.2.2
2 years ago
0.2.5
2 years ago
0.1.9
2 years ago
0.1.0
2 years ago
0.1.1
2 years ago
0.1.8
2 years ago
0.0.5
2 years ago
0.1.3
2 years ago
0.0.4
2 years ago
0.0.6
2 years ago
0.0.3
2 years ago