What is the correct fix?
el.addEventListener('scroll', () => heavy());
// later
el.removeEventListener('scroll', () => heavy());
- Keep one named handler and remove that
- Keep one inline arrow and remove that
- Pass
{ once: true }to the remove call - Call
el.removeEventListener('scroll')
The two arrows are different function objects, so the listener is never removed.
Play Problem Solving ▸