Next js router and useRouter

105 Views Asked by At
import { router } from "next/client";
import { useRouter } from "next/router";

const CustomComponent = () => {
  const routerFromHook = useRouter();
}

export default CustomComponent;

What is difference between router object and routerFromHook object? Which is better?

1

There are 1 best solutions below

0
On

First line of this documentation https://nextjs.org/docs/pages/api-reference/functions/use-router says that the useRouter is to be used inside a functional component when the router object is needed.