29 lines
611 B
TypeScript
29 lines
611 B
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
|
|
interface ClearParamsProps {
|
|
paramsToClear: string[];
|
|
}
|
|
|
|
export default function ClearParams({ paramsToClear }: ClearParamsProps) {
|
|
useEffect(() => {
|
|
if (typeof window === "undefined") return;
|
|
const url = new URL(window.location.href);
|
|
let changed = false;
|
|
|
|
paramsToClear.forEach((param) => {
|
|
if (url.searchParams.has(param)) {
|
|
url.searchParams.delete(param);
|
|
changed = true;
|
|
}
|
|
});
|
|
|
|
if (changed) {
|
|
window.history.replaceState({}, "", url.toString());
|
|
}
|
|
}, [paramsToClear]);
|
|
|
|
return null;
|
|
}
|