Closed nepomuc closed 2 years ago
Will it be hard for you if you send me a Git repo that replicates the problem?
@astoilkov Here you go: https://github.com/nepomuc/use-local-storage-state-issue-50-reproduced
Created this repo for reproducting this issue. I put some instructions for you into the README.md, so you can easily reproduce the hydration error.
Thanks in advance!
Thank you! I will take a look at this soon.
I found out what the problem is. As I suspected, SSR doesn't work in React 18. I've written about what are the steps for supporting React 18 here. However, this issue raises the priority of the task. When I switch to useSyncExternalStore()
API the issue will be fixed automatically.
Thanks for the repo and detailed information. I will write here when I'm done with the React 18 support and this issue is resolved.
I have the same error and it's cause Im using React 18. I decided to wait for the new version, but in the meantime, I have got around the problem by doing useIsClient
hook before my html renders. Since it's a side project and not in production yet, I'm not in a rush and workaround does me just fine.
import { useEffect, useState } from 'react';
/**
* Let's us know if we are on the Client or the Server
*/
export default function useIsClient() {
const [isClient, setClient] = useState(false);
useEffect(() => {
setClient(true);
}, []);
return isClient;
}
This issue is now fixed. The new version of use-local-storage-state supports React 18. You can upgrade.
I will close this issue but please let me know if you have a problem with the new version.
Thanks!
@astoilkov Works like a charm. Thanks a lot! 👍
Using next 12.1.6 and react 18.1.0 I get a hydration error when using use-local-storage-state, even though I'm using the ssr:true option.
I'm setting it up like that:
And I'm using it like that to show a div when
introductionFinished
is true:Here's my error log: