"Works" is in quotes because there's still a problem with this one, which is that the initial state still flashes. In your CodeSandbox, it briefly shows "Day" before being reset to the sticky value.
The ideal solution would be to hide this component until it's rendering on the client. It's impossible for the "initial" painted value to have the correct value, since the server has no idea what value is stored in your computer's localStorage.
Incidentally my next blog post will be on this subject, so I'll have more info then :D
Right! So I realized, my solution wasn't actually great for SSR 😬
It turns out this is a really hard problem for SSR. Here's a version that "works":
"Works" is in quotes because there's still a problem with this one, which is that the initial state still flashes. In your CodeSandbox, it briefly shows "Day" before being reset to the sticky value.
The ideal solution would be to hide this component until it's rendering on the client. It's impossible for the "initial" painted value to have the correct value, since the server has no idea what value is stored in your computer's localStorage.
Incidentally my next blog post will be on this subject, so I'll have more info then :D
Sorry for the confusion!
Oh. I see. this makes sense.
Looking forward to you blog post :)
cheers.