skip to Main Content

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


  1. actually would be twice , because it enabled StrictMode in dev

    https://zh-hant.reactjs.org/docs/strict-mode.html

    Login or Signup to reply.
  2. That is expected, see the detailed explanation here, and some possible methods for optimizing: https://github.com/vercel/next.js/issues/12010

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search