Kiarash-Z / react-modern-calendar-datepicker

A modern, beautiful, customizable date picker for React
https://kiarash-z.github.io/react-modern-calendar-datepicker/
MIT License
1.02k stars 217 forks source link

[bug] React 17 support #232

Open daniele-orlando opened 3 years ago

daniele-orlando commented 3 years ago

This lines breaks on React 17.

https://github.com/Kiarash-Z/react-modern-calendar-datepicker/blob/0cd7478b2fda3f755f0128a2ba1244346ed9eba0/src/Calendar.js#L47

React 17 changes the way references are handled for unmounted components. They are cleared right after the component is unmounted, but the effect unmount function is called later on. This means that references values must be stored in a local variable other wise they are undefined. https://it.reactjs.org/blog/2020/08/10/react-v17-rc.html#potential-issues

That portion of code should be rewritten as

useEffect(() => {
    const element = calendarElement.current
    const handleKeyUp = ({ key }) => {
      /* istanbul ignore else */
      if (key === 'Tab') element.classList.remove('-noFocusOutline');
    };
    element.addEventListener('keyup', handleKeyUp, false);
    return () => {
      element.removeEventListener('keyup', handleKeyUp, false);
    };
});
Hainesy commented 3 years ago

Duplicate of https://github.com/Kiarash-Z/react-modern-calendar-datepicker/issues/204