next13-progressbar icon indicating copy to clipboard operation
next13-progressbar copied to clipboard

`useRouter` hook is not memoized

Open alexcracea opened this issue 11 months ago • 2 comments

Describe the bug When using use useRouter hook from next13-progressbar it is never memoized and causes an infinite loop when using it as a dependency for useEffect

To Reproduce Steps to reproduce the behavior:

import { useEffect } from "react";
import { useRouter } from "next13-progressbar";

export function Example() {
  const router = useRouter();

  useEffect(() => {
    console.log("I will infinitely repeat");
  }, [router]);

  return (
    <div>
      <h1>Example</h1>
    </div>
  );
}

Expected behavior The useRouter instance should never re-trigger a change when used inside a useEffect

alexcracea avatar Mar 16 '24 08:03 alexcracea

I don't know but in my case using it as dependency in useEffect don't cause infinite loop. So maybe you can check if there may be another reason for it.

ndungtse avatar Mar 20 '24 17:03 ndungtse

This is happening with me as well, including router in my useEffect is causing an infinite repeat. Using Next.js 14 with Typescript

Edit: Using the normal Next.js router doesn't do an infinite repeat.

Kazizodev avatar Aug 29 '24 22:08 Kazizodev