Uncaught (in promise) TypeError: Cannot read properties of null (reading 'style')
dnish opened this issue · 3 comments
dnish commented
Hey,
thank you for the great component. We currently tried to implement it, but getting the following error when we create a new array after a user has swiped all available users:
TypeError: Cannot read properties of null (reading 'style')
It's happening here:
element.current.style.display = 'none'
if (onCardLeftScreen) onCardLeftScreen(dir)
I guess the problem is that the animation is running while the component gets unmuted because of the new array. Maybe we can check if the element.current is still defined before we apply the style.
3DJakob commented
When using useRef
you should always check that element.current != null
before accessing it because there are no guarantees that the element actually exists in the DOM.
Does that help?
dnish commented
Yes, I've forked it and changed the line in index.js
to this:
if(element && element.current) element.current.style.display = 'none';
This one works without problems.
3DJakob commented
Perfect!