Do component static properties get stripped in Next.js somehow or what??
Unanswered
Nile Crocodile posted this in #help-forum
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:
Should be able to do this
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
@Nile Crocodile 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
Have you tried logging the props?
@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.
@Nile Crocodile 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
Wait, a "non-client" component?
Server components don't exactly stay as components btw
Server components don't exactly stay as components btw
@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
I might be slightly wrong about this though ^