Next.js Discord

Discord Forum

Do component static properties get stripped in Next.js somehow or what??

Unanswered
Nile Crocodile posted this in #help-forum
Open in Discord
Nile CrocodileOP
I'm trying to assign static properties to components, and I've tried every way imaginable, but nothing seems to work.

Minimal example:
'use client';

export interface LinkProps
  extends Pick<
      ButtonProps,
      | 'variant'
      | 'color'
      | 'size'
      | 'startIcon'
      | 'endIcon'
      | 'loadingIndicator'
      | 'loading'
      | 'tooltip'
      | 'tooltipProps'
      | 'disabled'
      | 'children'
      | 'className'
    >,
    Omit<LinkPrimitiveProps, 'href'>,
    Pick<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'target' | 'rel'> {
  href: string | UrlObject;

const LinkComponent: React.FC<LinkProps> = ({
  children,
  href,
  color,
  variant,
  ...props
}) => {
  return (
      <NextLink href={href} {...props}>
        {children}
      </NextLink>
  );
};

/**
 * Attach the static properties to the Button component.
 */
const Link = Object.assign(LinkComponent, {
  Colors,
  Sizes,
  Variants
});

export { Link };



Should be able to do this
<Link
  color={Link.Colors.RED}
  variant={Link.Variants.FILL}
  href={href}
>
  Hello
</Link>

14 Replies

Nile CrocodileOP
Bump.
Rose-breasted Grosbeak
are you sure NextLink component accepts props like color and variant ?
try logging the props in LinkComponent, you'll find out.
Nile CrocodileOP
NextLink in particular is just what I'm using in this component, but yes my Link component accepts those props. You can try it with a normal div. It doesn't work.
I've figured out that the static props work fine in a client component, because Link is a client component. But I've moved the static properties to a non-client component, but it still doesn't work.
Rose-breasted Grosbeak
a div doesn't accept color and variant props either
@Rose-breasted Grosbeak a div doesn't accept color and variant props either
Nile CrocodileOP
...It does if you have props for them... I'm not passing them directly to the div, I'm utilizing them in the component.
@Rose-breasted Grosbeak Have you tried logging the props?
Nile CrocodileOP
Yes, they log fine in client components, but not server components.
Right. That's what I'm trying to figure out, if there's any way to do this. And it doesn't seem like it, other than converting the pages to client components, which I don't want to do.
Rose-breasted Grosbeak
You can do server-server or client-client
It wouldn't work across server-client because it doesn't stay in a JSX component form
I might be slightly wrong about this though ^