webraptor / react-native-deck-swiper

tinder like react-native deck swiper
ISC License
134 stars 83 forks source link

Fix #13 #39

Closed gfpacheco closed 1 year ago

gfpacheco commented 3 years ago

I'm new to this package, could you just make sure I didn't break anything else with this change?

I'm re-setting cards indexes and the cards state whenever the cards prop changes.

gfpacheco commented 3 years ago

I could re-set the state only if the length of the cards change if you think that's safer

webraptor commented 3 years ago

@gfpacheco using getDerivedStateFromProps isn't really recommended and the swiper actually had it a while back and was removed for multiple reasons, one of which is performance. The current issue mentioned happens likely because there's a mix of state / props in the swiper when there should be only props.

gfpacheco commented 3 years ago

I totally agree! I think the cards state is unnecessary, but I wanted to share the code that fixed the issue for me.

At the same time, we need to update the state whenever the cards prop changes (even before the render that changing it would cause), otherwise we might end up trying to read a card from an index that doesn't exist anymore.

Rotemy commented 3 years ago

getDerivedStateFromProps also fixes an issue for me when the card is null