自定义hooks
在 src 目录下新建 hooks/index.ts 模块,自定义hooks都写在这里,自定义hooks都以use开头
自定义封装鼠标位置的 hook
export const useMousePosition = (delay:number = 0) => {
const [position, setPosition] = useState({
x: 0, y: 0 }) // 鼠标的位置
useEffect(() => {
let timeId : null | NodeJS.Timeout = null
const mouseMoveHandler = (e: MouseEvent) => {
if(timeId !== null) return
timeId = setTimeout(() => {
console.log(