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

Ref calendarElement is null causes "Cannot read property 'removeEventListener' of null" #204

Open felixkoch opened 3 years ago

felixkoch commented 3 years ago

First: Thank you for this awesome Calendar Datepicker!

After updating to React 17 and next.js 10, removing the Calendar Component from DOM causes error "Cannot read property 'removeEventListener' of null" inside the Cleanup function of the useEffect hook in cases when the Ref to the calendarElement is not initialized properly.

mskarimi commented 3 years ago

me too @Kiarash-Z hi There is an update for this bug on react 17?

seyyed-sina commented 3 years ago

same issue here @Kiarash-Z

barghi commented 3 years ago

same issue here

ramirobg94 commented 3 years ago

other here

elin-oh commented 3 years ago

same issue

Adamkaram commented 3 years ago

same

seyyed-sina commented 3 years ago

any plan to fix the issue @Kiarash-Z??

bragayuri commented 3 years ago

same

thegauravthakur commented 3 years ago

same

Hosein-mh commented 3 years ago

same issue

mojabyte commented 3 years ago

As the maintainers didn't respond, I published the fixed version to my npm packages.

You can download and install it using:

npm install --save @hassanmojab/react-modern-calendar-datepicker

Then change all the imports to:

import '@hassanmojab/react-modern-calendar-datepicker/lib/DatePicker.css';
import DatePicker from '@hassanmojab/react-modern-calendar-datepicker';

⚠️ This is a temporary package as a solution just for this issue and won't be developed.

thegauravthakur commented 3 years ago

@HassanMojab works great!! Thanks

Hosein-mh commented 3 years ago

@HassanMojab it works but got warning: index.js:1446 Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering while sliding

Mehdi-Momenpoor commented 3 years ago

@HassanMojab

Thank you bro it worked for me without any warning.

well done!

max-oyedele commented 3 years ago

@HassanMojab It works. Thanks a lot.

farhadddvarjavand commented 3 years ago

if get it in github and use it in your project u must change src/calender.js this part of code: useEffect(() => { const handleKeyUp = ({ key }) => { /* istanbul ignore else / if (key === 'Tab') calendarElement.current.classList.remove('-noFocusOutline'); }; calendarElement.current.addEventListener('keyup', handleKeyUp, false); return () => { calendarElement.current.removeEventListener('keyup', handleKeyUp, false); }; }); to::::::::=>=>=>

useEffect(() => { const handleKeyUp = ({ key }) => { / istanbul ignore else / if (key === 'Tab') calendarElement.current.classList.remove('-noFocusOutline'); }; if(calendarElement.current.removeEventListener('keyup', handleKeyUp, false)){ calendarElement.current.addEventListener('keyup', handleKeyUp, false);

return () => { calendarElement.current.removeEventListener('keyup', handleKeyUp, false); }; } });

norama commented 3 years ago

Works for me, too, Thanks, I really appreciate. Sources on GitHub were a bit hard to find: https://github.com/hassanmojab/react-modern-calendar-datepicker because the source code of the original package is referenced from npm. I would like to fork this and do some minor bug fixes as well as solve the display of more months, I need 3 months.

wangtiger317 commented 3 years ago

@HassanMojab works great!! Thanks

yes, I have fixed it with this. thanks

s10mcow commented 3 years ago

+1

amir04lm26 commented 2 years ago

Here's the solution: https://github.com/Kiarash-Z/react-modern-calendar-datepicker/issues/284#issuecomment-950307226

jsina commented 2 years ago

@amir04lm26 as you see in the picture, the starting week day is "جمعه". I've already set the locale='fa' but the starting week index does not change. do u have any workaround?

Screen Shot 1400-11-21 at 00 56 28
reza-ya-57 commented 2 years ago

As the maintainers didn't respond, I published the fixed version to my npm packages.

You can download and install it using:

npm install --save @hassanmojab/react-modern-calendar-datepicker

Then change all the imports to:

import '@hassanmojab/react-modern-calendar-datepicker/lib/DatePicker.css';
import DatePicker from '@hassanmojab/react-modern-calendar-datepicker';

⚠️ This is a temporary package as a solution just for this issue and won't be developed.

hasan jan nejatemoon dadi damet garm

samyarkd commented 2 years ago

is there any update for this issue

amir04lm26 commented 2 years ago

@amir04lm26 as you see in the picture, the starting week day is "جمعه". I've already set the locale='fa' but the starting week index does not change. do u have any workaround?

Screen Shot 1400-11-21 at 00 56 28

please report the bug on my repo if you are assure of it

sarafiuter commented 2 years ago

GRACIAS GRACIAS GRACIAS

cheelix commented 10 months ago

Warning: J: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.

Cow258 commented 4 months ago

I have updated my forked repository to support React 19.

Can try it out by modify your package.json as follows

{
  "dependencies": {
    "react-modern-calendar-datepicker": "github:Cow258/react-modern-calendar-datepicker#built"
  }
}

or

npm install --save github:Cow258/react-modern-calendar-datepicker#built
yarn add github:Cow258/react-modern-calendar-datepicker#built
pnpm i github:Cow258/react-modern-calendar-datepicker#built