I’m trying to learn NextJS v13.2.4. So I’m kinda trying things out and I noticed that my route components are getting rendered 4 times. I don’t know if it’s because of development mode or somthing else. So is it normal ?
Here’s mo code :
import { useRouter } from "next/router";
import React from "react";
const PortfolioProjectPage = () => {
const router = useRouter();
console.log(router.query);
return <h1>PortfolioProjectPage</h1>;
};
export default PortfolioProjectPage;
and in the console I get this when I visit http://localhost:3000/portfolio/bridge route:
Object { } [projectid].js:6:10
Object { } bridge:1861:29
Object { projectid: "bridge" } [projectid].js:6:10
Object { projectid: "bridge" } bridge:1861:29
2
Answers
actually would be twice , because it enabled StrictMode in dev
https://zh-hant.reactjs.org/docs/strict-mode.html
That is expected, see the detailed explanation here, and some possible methods for optimizing: https://github.com/vercel/next.js/issues/12010