Advertisement
dbarrera

App.js

Feb 8th, 2022
1,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {useState, useEffect} from 'react';
  2. import ReactDOM from 'react-dom';
  3. import Coordenadas from './Coordenadas'
  4.  
  5. const App = () => {
  6.   const mouseListener = () => window.addEventListener('mousemove', change);
  7.  
  8.   const [vis, setVisibilidad] = useState(false);
  9.   const [mX, getMouseX] = useState(0);
  10.   const [mY, getMouseY] = useState(0);
  11.  
  12.   const alterarVisibilidad = () => {
  13.     setVisibilidad((vis) => !vis);
  14.   }
  15.  
  16.   useEffect(() => {
  17.     mouseListener();
  18.   })
  19.  
  20.   const change = (e) => {
  21.     getMouseX(e.clientX)
  22.     getMouseY(e.clientY)
  23.   }
  24.  
  25.  
  26.   return <div>
  27.     {vis ? <Coordenadas coordX={mX} coordY={mY} /> : <div>Oculto</div> }
  28.     <button type='button' onClick={alterarVisibilidad}>Visibilidad</button>
  29.   </div>
  30. }
  31.  
  32. ReactDOM.render(<App />, document.querySelector("#root"));
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement