Kiarash-Z / react-modern-calendar-datepicker

A modern, beautiful, customizable date picker for React

Home Page:https://kiarash-z.github.io/react-modern-calendar-datepicker/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

felixkoch opened this issue · 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.

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

same issue here

other here

same issue

same

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

same

same issue

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.

@hassanmojab works great!! Thanks

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

commented

@hassanmojab

Thank you bro
it worked for me without any warning.

well done!

@hassanmojab
It works.
Thanks a lot.

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

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.

@hassanmojab works great!! Thanks

yes, I have fixed it with this. thanks

+1

commented

Here's the solution: #284 (comment)

@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

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

is there any update for this issue

commented

@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

GRACIAS GRACIAS GRACIAS

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

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