-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next.js className function problem #1575
Comments
@theeldarka |
Hey! Unfortunately you can't pass functions/callbacks to components in server components because they are not serializable. In this case you can do a few things:
For example, this: <Popover
as="header"
className={({ open }) =>
classNames(
open ? 'fixed inset-0 z-40 overflow-y-auto' : '',
'bg-white shadow-sm lg:static lg:overflow-y-visible'
)
}
> ... turns into something like this: <Popover
as="header"
className="data-[open]:fixed data-[open]:inset-0 data-[open]:z-40 data-[open]:overflow-y-auto bg-white shadow-sm lg:static lg:overflow-y-visible"
{/* ---------------------------------------------------------------------------------- */}
> Notice how each class that used to be added based on the In case you are showing elements conditionally, you can also use So code like this: <Popover>
{open ? (
<XMarkIcon className="block h-6 w-6" aria-hidden="true" />
) : (
<Bars3Icon className="block h-6 w-6" aria-hidden="true" />
)}
</Popover> ... turns into this: <Popover className="group">
<XMarkIcon className="group-data-[open]:block hidden h-6 w-6" aria-hidden="true" />
<Bars3Icon className="group-data-[open]:hidden block h-6 w-6" aria-hidden="true" />
</Popover> All that said, maybe Next.js and React will one day figure out on how to serialize functions, but for now this is what you have to do. We will also very likely convert our Tailwind UI components to make use of these data attributes which will simplify the components more. Hope this helps! |
What component (if applicable)
Describe the bug
I guess, Next.js has upgraded and now they don't support functions to className attribute on the client side
To Reproduce
Steps to reproduce the behavior:
The text was updated successfully, but these errors were encountered: