ndungtse / next13-progressbar

A simple Next.js progressbar component using NProgress with support of next.js >=13 app dir.
https://next13-progressbar.vercel.app
MIT License
86 stars 3 forks source link

`useRouter` hook is not memoized #28

Open alexcracea opened 4 months ago

alexcracea commented 4 months ago

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

ndungtse commented 4 months ago

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.