fix: navigating to other pages redirects back

This commit is contained in:
trafficlunar 2025-07-19 17:47:28 +01:00
parent d07383b251
commit b8f2f216a3

View file

@ -23,6 +23,11 @@ export default function TagFilter() {
const [tags, setTags] = useState<string[]>(preexistingTags); const [tags, setTags] = useState<string[]>(preexistingTags);
// Sync state if the URL tags change (e.g. via navigation)
useEffect(() => {
setTags(preexistingTags);
}, [preexistingTags]);
// Redirect automatically on tags change // Redirect automatically on tags change
useEffect(() => { useEffect(() => {
const urlTags = preexistingTags.join(","); const urlTags = preexistingTags.join(",");
@ -40,7 +45,8 @@ export default function TagFilter() {
startTransition(() => { startTransition(() => {
router.push(`?${params.toString()}`); router.push(`?${params.toString()}`);
}); });
}, [tags, preexistingTags, searchParams, router]); // eslint-disable-next-line react-hooks/exhaustive-deps
}, [tags]);
return ( return (
<div className="w-72"> <div className="w-72">