react-scan icon indicating copy to clipboard operation
react-scan copied to clipboard

[Question] How do you unmount the scan?

Open TatisLois opened this issue 10 months ago • 3 comments

Framework: Next.JS/Web Routing: App Router (client)

Question:

I am using a flag called reactScan that can be toggled true/false from a dev tool panel. The issue I've run into is when the flag is toggled false from being true the toolbar does not get removed from the application.

It does seem to stop (some actions), likely because of the setOptions/enabled:false that I'm calling on unmount.

What is the right way to unmount from react scan or is that not supported? If it's a bug/improvement/ happy to attempt a PR :)

Sample Code

import { scan, setOptions } from "react-scan"; // import this BEFORE react

 useEffect(() => {
    if (typeof window !== "undefined" && reactScan) {
      scan({
        enabled: true,
      });
    }

    return () => {
      setOptions({
        enabled: false,
      });
    };
  }, [reactScan]);

Thank you

TatisLois avatar Dec 05 '24 18:12 TatisLois