Spaces:
Sleeping

naohiro701 commited on
Commit
b2010f0
·
verified ·
1 Parent(s): e3aecc1

Create my_mouse_tracker/frontend/src/index.js

Browse files
my_mouse_tracker/frontend/src/index.js ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // my_mouse_tracker/frontend/src/index.js
2
+ import React, { useEffect } from "react";
3
+ import { Streamlit, withStreamlitConnection } from "streamlit-component-lib";
4
+
5
+ const MouseTracker = () => {
6
+ useEffect(() => {
7
+ const handleMouseMove = (event) => {
8
+ const { clientX, clientY } = event;
9
+ Streamlit.setComponentValue({ x: clientX, y: clientY });
10
+ };
11
+
12
+ window.addEventListener("mousemove", handleMouseMove);
13
+
14
+ return () => {
15
+ window.removeEventListener("mousemove", handleMouseMove);
16
+ };
17
+ }, []);
18
+
19
+ return null;
20
+ };
21
+
22
+ export default withStreamlitConnection(MouseTracker);