You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
ritwickdey
changed the title
Bugs in the code. removeEventListener will not work properly.
[BUG]removeEventListener will not work properly.
Jul 26, 2019
ritwickdey
added a commit
to ritwickdey/online-status
that referenced
this issue
Jul 26, 2019
Every-time when state will update,
goOnline
andgoOffline
will get re-defined (means, new memory location - different reference).When the hook will run for first time,
addEventListener
will attach first reference of thegoOnline
orgoOffline
. And then when the state will update, we will get new reference ofgoOnline
andgoOffline
. so, we need to move the 2 functions inside ofuseEffect
, so that it'll not be redefined again and again.online-status/src/index.js
Lines 11 to 26 in 389c994
The text was updated successfully, but these errors were encountered: