useEffect might be better than useState
Closed this issue · 3 comments
Hi there,
I noticed that this implementation uses useState instead of useEffect. Since changing cookies is a side effect, wouldn't useEffect be better?
Hi Michael,
It's likely you're right that implementation using useEffect
would be better. However, I'd like to keep it as close as possible to js-cookie and provide getter
and setter
for cookie value without subscriptions (at least for now).
But maybe you could provide an example or suggestion of how get rid of useState
and use useEffect
instead, simultaneously keeping setter function?
Thanks for your feedback!
Yes the ideal solution would be the cookie as the source of truth. There is an API for this: https://developer.mozilla.org/fr/docs/Mozilla/Add-ons/WebExtensions/API/cookies/onChanged
Unfortanutally, it's not standard
@titouancreach thanks for mentioning this API
Until it isn't a standard I would leave hook functionality as it is, due potential compatibility issues.