Next.js Discord

Discord Forum

code runs 4 times in client and twice on server ??!

Answered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
Hello, I'm having trouble rendering an image
I'm fetching the image url from a strapi backend, and passing it into a component as the src of the Inage (next/image)
The image isn't rendered on the page, and when I console.log the src to see if it's a string or undefined, I get the following in my terminals (+check images - teal bcg is terminal, other is firefox devtools)

Here's my component's code
"use client";

// ? React Imports
import * as React from "react";

// ? Next Imports
import Image from "next/image";

// ? Component Imports
import {
  NavigationMenu,
  NavigationMenuList,
} from "@/app/[lang]/components/ui/navigation-menu";
import NavLarge from "@/app/[lang]/components/NavMenu/Large";
import NavMedium from "@/app/[lang]/components/NavMenu/Medium";

export default function NavMenu({
  logoUrl,
}: {
  logoUrl: string | null
}) {
  console.log(logoUrl);

  return (
    <NavigationMenu className="w-screen fixed top-0 h-[70px] bg-s-bg-primary z-40 shadow-[0px_-40px_40px_5px_#81e6d9]">
      <NavigationMenuList className="w-screen justify-start" id="nav-menu">
        <Image
          src={logoUrl ? logoUrl : "/logo.png"}
          className="ml-5"
          alt="logo"
          width="70"
          height="70"
        />
        <NavLarge />
        <NavMedium />
      </NavigationMenuList>
    </NavigationMenu>
  );
}

I have set react strict mode to false
Here's how I'm passing the url to the component
<NavMenu logoUrl={navbarLogoUrl} />
Answered by Spectacled bear
nvm it was a routing issue afterall, code was doing what it was supposed to, developer is dumb
View full answer

7 Replies

Antillean Nighthawk
Hello add youre image url into the next.cinfig.js file like this
Spectacled bearOP
won't this do?
I don't think the issue is with my nextjs configuration, because the console.log() i have in the component's code prints 1x undefined and 1x the url in the terminal, and 3x undefined and 1x the url in the web console
Spectacled bearOP
nvm it was a routing issue afterall, code was doing what it was supposed to, developer is dumb
Answer
Antillean Nighthawk
try to use react useState it will solve the problem
Spectacled bearOP
Haven't 100% solved the problem but images work in /home but not in /test (for example)
@Antillean Nighthawk try to use react useState it will solve the problem
Spectacled bearOP
will do, thanks!