reactivers / use-cookie

Cookie management in React with hooks in providers.
1 stars 1 forks source link

Not grabbing initial cookies from browser on load? #2

Open sdoxsee opened 11 months ago

sdoxsee commented 11 months ago

Enjoying this light dependency but facing an issue....

I wrap my app in the CookieProvider and then initially do a getItem("my-cookie"). I seem to only be getting the value back after I've done setItem("my-cookie", "my-value").

Does the CookieProvider only handle what is set after-the-fact?

Thanks!

mrtgny commented 10 months ago

Hi @sdoxsee ,

We are so happy to hear that you enjoy using the library 😊

It seems the problem is the way you use the setItem function. You should pass a expireDays or expireHours like setItem({ key: "my-cookie", value: "test", expireDays: 1 })

To learn more you can check the docs

If you face any other problem, please feel free to contact us 👍😊