Open Rimberse opened 1 year ago
works fine in codesandbox
works fine in codesandbox
It works if everything is a client component, and you import from next-ui/react
.
However, if you use it as a server component and then try to import it from next-ui/card
the issue can be reproduced.
I was able to reproduce it by doing the above steps in your sandbox: codesandbox
Here is my recreation of this issue: Codesandbox When you refresh the page, hydration error occurs.
+1
+1
@aaronhawkey can you try the following
// app/providers.tsx
"use client";
import { useEffect, useState } from "react";
import { NextUIProvider } from "@nextui-org/react";
export function Providers({ children }) {
const [isClient, setIsClient] = useState(false);
useEffect(() => {
setIsClient(true);
}, []);
return isClient ? <NextUIProvider>{children}</NextUIProvider> : <></>;
}
I had this exact problem. My problem was that I had a<Button/>
inside a <Card/>
with isPressable
property, and as you said, that was like having a button inside a button. I removed the property and its working fine.
This fixed my hydration issue: https://github.com/nextui-org/nextui/issues/2073#issuecomment-1953728672
@aaronhawkey can you try the following
// app/providers.tsx "use client"; import { useEffect, useState } from "react"; import { NextUIProvider } from "@nextui-org/react"; export function Providers({ children }) { const [isClient, setIsClient] = useState(false); useEffect(() => { setIsClient(true); }, []); return isClient ? <NextUIProvider>{children}</NextUIProvider> : <></>; }
for me on using this method, nothing renders but a black page and errors on console.
// app/providers.tsx
"use client";
import { useEffect, useState } from "react";
import { NextUIProvider } from "@nextui-org/react";
export function Providers({ children }) {
const [isClient, setIsClient] = useState(false);
useEffect(() => {
setIsClient(true);
}, []);
return isClient ? <NextUIProvider>{children}</NextUIProvider> : {children};
}
the above works but then useEffects are called multiple times(which is expected) because components are mounted and remounted when isClient becomes true
😁 just realized it didn't work for me because I had the following structure
<Provider>
<body></body>
</Provider>
all my providers are in <Provider>
so by doing return isClient ? <NextUIProvider>{children}</NextUIProvider> : <></>;
inside my provider, it meant my entire document didn't have a body
tag at some point.
rearranging stuff like this, fixed it
<body>
<Provider>
</Provider>
</body>
still happen right now, NextJS 14 page route That's a joke, even a button also have bug that's need a useEffect hack to fix
<></>;
You saved me hours of searching. Thank You!
<></>;
You saved me hours of searching. Thank You!
What do you mean how to use react fragements and where?
NextUI Version
2.2.9
Describe the bug
Hello,
Upon trying to use the card component's
isPressable
property within Next.js i get this error: https://nextui.org/docs/components/card#primary-actionThe card itself renders fine without this property. If I am understanding correctly the issue is that
<Card />
converts to<Button />
during rendering and considering that it has nested<div>
elements within it triggers this error. Is there a way to avoid it? What's the fix?Your Example Website or App
http://localhost:3000
Steps to Reproduce the Bug or Issue
npm run dev
isPressable
propertyExpected behavior
The card component should render without issues.
isPressable
property should not cause any console errors on runtime.Screenshots or Videos
Operating System Version
Windows
Browser
Chrome