react-modern-calendar-datepicker icon indicating copy to clipboard operation
react-modern-calendar-datepicker copied to clipboard

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

Open felixkoch opened this issue 4 years ago • 27 comments

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.

felixkoch avatar Nov 03 '20 12:11 felixkoch

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

mskarimi avatar Nov 22 '20 12:11 mskarimi

same issue here @Kiarash-Z

seyyed-sina avatar Nov 24 '20 14:11 seyyed-sina

same issue here

barghi avatar Nov 29 '20 08:11 barghi

other here

ramirobg94 avatar Dec 01 '20 09:12 ramirobg94

same issue

elin-oh avatar Dec 09 '20 13:12 elin-oh

same

Adamkaram avatar Dec 13 '20 12:12 Adamkaram

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

seyyed-sina avatar Dec 22 '20 15:12 seyyed-sina

same

bragayuri avatar Dec 23 '20 13:12 bragayuri

same

thegauravthakur avatar Dec 30 '20 17:12 thegauravthakur

same issue

Hosein-mh avatar Jan 05 '21 12:01 Hosein-mh

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.

mojabyte avatar Jan 10 '21 18:01 mojabyte

@HassanMojab works great!! Thanks

thegauravthakur avatar Jan 11 '21 03:01 thegauravthakur

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

Hosein-mh avatar Jan 13 '21 13:01 Hosein-mh

@HassanMojab

Thank you bro it worked for me without any warning.

well done!

Mehdi-Momenpoor avatar Jan 24 '21 14:01 Mehdi-Momenpoor

@HassanMojab It works. Thanks a lot.

max-oyedele avatar Apr 22 '21 01:04 max-oyedele

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); }; } });

farhadddvarjavand avatar Apr 30 '21 18:04 farhadddvarjavand

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.

norama avatar May 06 '21 16:05 norama

@HassanMojab works great!! Thanks

yes, I have fixed it with this. thanks

wangtiger317 avatar Jun 15 '21 17:06 wangtiger317

+1

s10mcow avatar Jun 24 '21 13:06 s10mcow

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

amir04lm26 avatar Oct 24 '21 11:10 amir04lm26

@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

jsina avatar Feb 09 '22 21:02 jsina

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

reza-ya-57 avatar Feb 12 '22 10:02 reza-ya-57

is there any update for this issue

samyarkd avatar Apr 27 '22 09:04 samyarkd

@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

amir04lm26 avatar Apr 27 '22 10:04 amir04lm26

GRACIAS GRACIAS GRACIAS

sarafiuter avatar Aug 31 '22 07:08 sarafiuter

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

cheelix avatar Nov 19 '23 06:11 cheelix