useRef for Hide popup when click body

  const [show, setShow] = useState(false);

  const [color, setColor] = useState({
    hue: 120,
    brightness: 0,
    saturation: 1,
  });
  const colorRef = useRef<HTMLDivElement | null>(null);
  const handleHide = (event: MouseEvent) => {
    if (colorRef.current && !colorRef.current.contains(event.target as Node)) {
      // Assuming you have a `setShow` function defined somewhere
      setShow(false);
    }
  };
  useEffect(() => {
    window.addEventListener("click", handleHide);
    return () => {
      window.removeEventListener("click", handleHide);
    };
  }, []);
Previous Code

react icons not working with remix-run?

You have to add serverDependenciesToBundle insid ...

skype

Need Coding Help?

Connect Skype

AI

DATABASE

Jobs

Nextjs

Node

Npm

PHP

Prisma

React

Remix-run

Shopify App

Shopify theme

tailwindcss

Tech

VPS

Woocommerce

WordPress

Convert Hex to hsb using js

...

Prisma config with Mongodb

1-Install the Prisma CLI: 2-Initialize a Prisma pr ...

18 Important HTTP Status Codes You Must Know 🔥

– 200 OK: Request succeeded– 201 Creat ...

essential Npm package for developers

Drag and drop image upload Use of the Npm package ...

Shopify Cli

Shopify.app.toml scope or config update Shopify pa ...

top