online-status
online-status copied to clipboard
[BUG]`removeEventListener` will not work properly.
Every-time when state will update, goOnline
and goOffline
will get re-defined (means, new memory location - different reference).
When the hook will run for first time, addEventListener
will attach first reference of the goOnline
or goOffline
. And then when the state will update, we will get new reference of goOnline
and goOffline
. so, we need to move the 2 functions inside of useEffect
, so that it'll not be redefined again and again.
https://github.com/rehooks/online-status/blob/389c994caa0b27b12ba5f18297f58f45482757df/src/index.js#L11-L26