12 lines · 411 B
import { useEffect } from "react";

/** Removes a one-time query parameter from the address bar once the page has read it. */
export function useStripSearchParam(name: string): void {
  useEffect(() => {
    const url = new URL(window.location.href);
    if (!url.searchParams.has(name)) return;
    url.searchParams.delete(name);
    window.history.replaceState(window.history.state, "", url);
  }, [name]);
}