Open mattproch opened 4 years ago
Hi @mattproch, I am having the same issue. I figured it is because of the Card Index. It initializes it with the maximum Card Index equal to the initial size of the cards Array. And if any element is deleted from cards Array or updated, it iterates over the same range of card indices, hence it will return undefined for items no longer present in Cards Array.
Were you able to find a fix?
Same problem here, I just create a pr for this. #318
PR #318 is yet to be merged in and it doesn't seem to fix this issue. A 'hacky' fix that I found to work is to set the key of the swipe component to be the stringified value of the cards. Any changes then forces a component remount and re-render. This results in the correct deck size being used.
Hey, I use this swiper with search results. If there is none (so
this.props.results
is[]
) or even if I manually docards={[]}
it still tries to render some and throw an errorTypeError: undefined is not an object (evaluating result.id)
I did some digging and the problem should be in
renderStack
method cause it does not do any validation of indexes. All it does is checkingswipedAllCards
but that is probably not actually valid before first swipe. So in constructor (my version line 48) should be something likeswipedAllCards: props.cards.length === 0
instead ofswipedAllCards: false
. Or probably something more stronger because of Maps, Sets etc.My solution for now is just not render the swiper at all if my results are empty but that is kind of ugly.