Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

Hydration failed because the initial UI does not match what was rendered on the server #9

Open
duck2913 opened this issue Aug 1, 2022 · 0 comments

Comments

@duck2913
Copy link

duck2913 commented Aug 1, 2022

I was implementing creating the user store with zustand and then stumbled into this error.

image

I think that the reason is since we are using SSR from NextJS so the page will be rendered on the server and the server can't access the client's storage

My solution is not to use the userProfle from the useAuthStore hook to render the profile image, but to use a local state myUser

const { userProfile, addUser, removeUser } = useAuthStore();
const [myUser, setMyUser] = useState<IUser>(null);

useEffect(() => {
  setMyUser(userProfile);
  }, [userProfile]);
{myUser && (
  <div className="flex items-center gap-10">
	  <button className="flex gap-2 items-center border-2 rounded-md border-gray-300 p-3 py-1 hover:text-pink-700 hover:border-pink-600 transition duration-500">
		  <IoMdAdd />
		  Upload
	  </button>
    .....

I hope this will help anyone who comes across this issue.

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

No branches or pull requests

1 participant