Last active
August 20, 2021 04:51
-
-
Save bigopon/9cb8038bde99fdbb0a202d17765da32e to your computer and use it in GitHub Desktop.
react link mouse down vs click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Dumber Gist</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"> | |
</head> | |
<!-- | |
Dumber Gist uses dumber bundler, the default bundle file | |
is /dist/entry-bundle.js. | |
The starting module is pointed to "index" (data-main attribute on script) | |
which is your src/index.jsx. | |
--> | |
<body> | |
<div id="root"></div> | |
<script src="/dist/entry-bundle.js" data-main="index"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"react": "latest", | |
"react-dom": "latest" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
// Try to create a css/scss/sass/less file then import it here | |
export default function App() { | |
const [logs, setLogs] = React.useState([]); | |
return ( | |
<> | |
<a href="#hello/" | |
onMouseDown={e => { | |
console.log('mouse down', e.button); | |
const msg = `mouse down ${e.button}`; | |
setLogs([...logs, msg]); | |
}} | |
onClick={e => { | |
console.log('click', e.button); | |
const msg = `click ${e.button}`; | |
setLogs([...logs, msg]); | |
}}> | |
<h1>Hello React!</h1> | |
</a> | |
{logs.map((l, idx) => | |
<> | |
<div key={l + idx}>{l}</div> | |
{l.includes('click') && <hr />} | |
</>)} | |
</> | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import App from "./App"; | |
const rootElement = document.getElementById("root"); | |
ReactDOM.render(<App />, rootElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment