online-status icon indicating copy to clipboard operation
online-status copied to clipboard

[BUG]`removeEventListener` will not work properly.

Open ritwickdey opened this issue 5 years ago • 0 comments

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

ritwickdey avatar Jul 26 '19 11:07 ritwickdey