Created
April 11, 2020 12:22
-
-
Save merelinguist/4f4d409c9a551f449003681b8ef33632 to your computer and use it in GitHub Desktop.
This file contains 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 { useRef } from "react"; | |
import { MouseEvent } from "react"; | |
import { Header } from "../components/Header"; | |
import { Main } from "../components/Main"; | |
export default () => { | |
const boardRef = useRef<HTMLDivElement>(null); | |
const handleClick = (e: MouseEvent<HTMLDivElement>) => { | |
const rect = boardRef.current?.getBoundingClientRect(); | |
if (rect) { | |
const x = e.clientX - rect?.left; | |
const y = e.clientY - rect?.top; | |
console.log(x, y); | |
} | |
}; | |
return ( | |
<> | |
<Main> | |
<div className="max-w-xl mx-auto"> | |
<div | |
ref={boardRef} | |
onClick={handleClick} | |
className="bg-white shadow overflow-hidden sm:rounded-lg relative px-4 py-5 border-b border-gray-200 sm:px-6" | |
style={{ paddingTop: "100%" }} | |
/> | |
</div> | |
</Main> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment