Next.js Discord

Discord Forum

Is component duplication bad

Answered
! AlexNotTheLion posted this in #help-forum
Open in Discord
I made a mistake and designed desktop first, without consideration to mobile ui, In my navbar I've currently implemented a popover for a user inbox where they can see notifications and friend requests,
<div className="flex gap-12 w-full">
  <nav className="hidden w-full md:flex justify-between">
    ...
    <div className="flex gap-8 items-center">
      {signedIn ? <>
        <InboxPopover notifications={notifications} friends={friends} />
        <ProfileDropdown profile={profile!} friends={friends} />
      </>
        : <LoginDialog><Button>Login</Button></LoginDialog>}
    </div>
  </nav>
</div>
for mobile ui I've added a shadcn sheet :
<Sheet>
  <SheetTrigger asChild>
    <Button className="md:hidden" size="icon" variant="outline">
      <MenuIcon className="h-6 w-6" />
    </Button>
  </SheetTrigger>
  <SheetContent side={"right"} className="flex flex-col justify-between">
    <div className="grid gap-6 p-6">
      <Link className="font-medium hover:underline">
        Inbox
      </Link>
      <Separator />
      ...
      <Link className="font-medium hover:underline flex items-center">
        <User className="mr-2 h-4 w-4" />
        <span>Profile</span>
      </Link>
     ...
    </div>
  </SheetContent>
</Sheet>

this is all currently in a RSC, my question is:
should I design the navbar in a way to reduce as much component duplication as possible (this would involve turning the navbar component into a client component and using swr to do client side data fetching I believe)
Answered by Arinji
With simple media queries it works well
View full answer

33 Replies

inbox desktop reference
You shld have bumped this post a while ago xD
But code deduplication isn't that necessary
Usually with navbars it's better to just have 2 components since a PC navbar is much diff from a mobile one, and using media queries you render either or
@! AlexNotTheLion
@Arinji You shld have bumped this post a while ago xD
Yeah, i honestly didnt realise i could bump, but i tidied up the question a lot today 😄
All good, saw your structured rant today and was curious since if someone has such a detailed rant, they probably have a structured question as well
Just check screen width
ah right okay! in my currently version I have dialogs for the login and profile related things which are controlled from a use state so it uses the same dialog across devices, but that does force me to use "use client" which im not sure is a good or bad thing
Use client isn't bad
Original message was deleted
:meow_stare:
Sir, I'm cooking in this forum post
Go elsewhere
@Arinji Use client isn't bad
@! AlexNotTheLion either way your client components get rendered on the server
okay heres what i currently have in its entirety : https://pastebin.com/B6YYxUEx , are the benefits of doing conditional rendering vs the css equivalent ?
Normal screen width checking with js requires js to be present
Hence there is a delay
With media queries css is always present
so presumably it would still have to be a client component, as ssr wont know the screen width ?
@Arinji <:meow_stare:763826437341839422>
American Crow
LET HIM COOK 🧑‍🍳
@! AlexNotTheLion so presumably it would still have to be a client component, as ssr wont know the screen width ?
Yea without media queries it needs to be a client component
Even inside you need state
A use effect
Lots of stuff
With simple media queries it works well
Answer
i see! okay time to redesign xD
ty ty
Np
Mark a solution
Original message was deleted
@! AlexNotTheLion
@Arinji Mark a solution
ah yep!