fisshy / react-scroll

React scroll component
https://github.com/fisshy/react-scroll/blob/master/README.md
MIT License
4.36k stars 437 forks source link

New set of listeners created on each click, not removed on leave #451

Closed emilecollin closed 1 year ago

emilecollin commented 3 years ago

I have this React component:

import React from 'react';
import { animateScroll as scroll } from 'react-scroll';

const Test: React.FC = () => {
  const scrollToTop = () => {
    scroll.scrollToTop();
  };

  return <div onClick={scrollToTop}>Test</div>;
};

export default Test;

On each click, a new set of keydown, mousedown, mousewheel and touchmove are created. Here we have it on Chrome Devtools after four clicks:

wbahO

They are not removed on leave.

Not sure whats the usual procedure to remove them, but probably they should be cleaned for each click.