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

useCookies check for Provider doesn't work #452

Open
rstepinski opened this issue Jan 26, 2024 · 0 comments
Open

useCookies check for Provider doesn't work #452

rstepinski opened this issue Jan 26, 2024 · 0 comments

Comments

@rstepinski
Copy link

The useCookies hook contains a check for a wrapping Provider:

const cookies = useContext(CookiesContext);
if (!cookies) {
  throw new Error('Missing <CookiesProvider>');
}

Unfortunately, this never throws because CookiesContext has a default value, therefore cookies is always defined and the condition is always false:

const CookiesContext = React.createContext(new Cookies());

This ended up biting me with some hydration errors which were pretty hard to track down, and indeed I just forgot to wrap my layout with CookiesProvider.

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