Skip to content

Instantly share code, notes, and snippets.

View rayliao's full-sized avatar
📸
Focusing

Ray rayliao

📸
Focusing
View GitHub Profile
@rayliao
rayliao / utils.ts
Created June 3, 2022 12:40
React Skills
import { useEffect } from "react";
export const useOutsideClick = (
ref: React.RefObject<HTMLElement>,
callback: () => void
) => {
useEffect(() => {
const handleClick = (e: MouseEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) {
callback();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>INDEX</title>
<meta name="description" content="">
</head>
<body>
Hello World!