Skip to content

Instantly share code, notes, and snippets.

@bigopon
Last active August 20, 2021 04:51
Show Gist options
  • Save bigopon/9cb8038bde99fdbb0a202d17765da32e to your computer and use it in GitHub Desktop.
Save bigopon/9cb8038bde99fdbb0a202d17765da32e to your computer and use it in GitHub Desktop.
react link mouse down vs click
<!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>
{
"dependencies": {
"react": "latest",
"react-dom": "latest"
}
}
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 />}
</>)}
</>
);
}
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