Skip to content
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

Add dynamic loading as a way to avoid hydration mismatch in README #249

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Judge-Paul
Copy link

@Judge-Paul Judge-Paul commented Feb 3, 2024

This PR updates the README with another option to prevent hydration errors by dynamically loading the components with the unsafe code and setting ssr to false.
The new section would look like:

Avoid Hydration Mismatch

// unchanged

or lazy load the component setting ssr to false:

import dynamic from "next/dynamic";

const ThemeSwitch = dynamic(() => import("./ThemeSwitch"), { ssr: false });

const ThemePage = () => {
  return (
    <div>
      <ThemeSwitch />
    </div>
  );
};

export default ThemePage

To avoid Layout Shift, consider rendering a skeleton/placeholder until mounted on the client side.

Copy link

vercel bot commented Feb 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-themes-basic ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2024 6:20pm
next-themes-tailwind ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2024 6:20pm
next-themes-with-app-dir ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2024 6:20pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant