not work in Safari
KaroseLiu opened this issue · 7 comments
Safari not listen the change
codeSandboxlink: https://codesandbox.io/s/adoring-wright-y7cw2
Seems like we will need to polyfill for Safari and IE.
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
Anyone had any success with this?
I would try including the polyfill in the beginning of your code.
Perhaps use this implementation:
https://www.npmjs.com/package/custom-event-polyfill
I realized it might be a bit odd for us to stick it in our implementation, as we are just creating a react hook, as opposed to creating a react hook and polyfilling CustomEvent. Adding that global object might be a side effect you would want explicit control over.
@firzanarmani @jharrilim Even with custom-event-polyfill
it doesn't seem to work in Safari:
Unfortunately I'm not of much use for helping with this testing... I don't have a Mac. Does it show any error in the console?
The issue is that the check event instanceof LocalStorageChanged
doesn't work in Safari. If instead you check the type event.type === LocalStorageChanged.eventName
it will work. I'll try to submit a PR if I get a chance.