Next.js Discord

Discord Forum

Hydration error best practice

Unanswered
Siamese Crocodile posted this in #help-forum
Open in Discord
Siamese CrocodileOP
Hi. I am using Dialog from radix ui thats open based on the search params. I am experiencing hydration errors when I enter url localhost:3000?modal=login directly in the browser and I guess its because of prerendering - the dialog on the server did not render and on the client when nextjs was hydrating it did render.

I came up with two solutions but I am not sure which is better.

1. Create smth like useClient hook like in nextjs docs
const [isClient, setIsClient] = useState(false);

  useEffect(() => {
    setIsClient(true);
  }, []);

  return (
    <Dialog
      open={isClient && params.get('modal') === 'login'}


2. Import login modal using dynamic with ssr: false

9 Replies

Siamese CrocodileOP
Hm
I did not see any difference
when I tried both of these
Well… if it works it works, so…
If it works for you, I don’t see a reason why you would need to change