Cookies on the client
Is there an equivalent of getCookie, setCookie, parseCookie, etc from '@tanstack/react-start/server' but for the client? I'm trying to setup i18next and ran into hydration mismatches, so I'm trying to set it both on the server and the client from a cookie.
9 Replies
other-emerald•6mo ago
no. could maybe be a nice addition to add isomorphic versions of those functions
for now, you need to create your own via something like this
optimistic-goldOP•6mo ago
Thanks!
The client code is a bit hacky, but worked perfectly. Here is the code for anyone that may be interested (I'm using the user's browser as a fallback):
Use
setupI18n in client.tsx and server.ts and you are good to go.other-emerald•6mo ago
would use this for cookie parsing https://github.com/unjs/cookie-es
GitHub
GitHub - unjs/cookie-es: 🍪 Cookie and Set-Cookie parser and seri...
🍪 Cookie and Set-Cookie parser and serializer. Contribute to unjs/cookie-es development by creating an account on GitHub.
other-emerald•6mo ago
(on the client)
optimistic-goldOP•6mo ago
I will take a look, thanks!
correct-apricot•6mo ago
was actually searching for this the other day :p need to pin unjs tools to visit more often 😄, thanks
conscious-sapphire•6mo ago
Could you solve this hydration problem?
optimistic-goldOP•6mo ago
Yes, using isomorphic functions does the trick
xenial-black•6mo ago
Thanks for this thread, i will check it out 😍😍