alexbrillant / react-native-deck-swiper

tinder like react-native deck swiper
ISC License
1.54k stars 460 forks source link

Functional Component ref is not working (swiperRef is undefined) #362

Open iamadityaaz opened 3 years ago

iamadityaaz commented 3 years ago
  const swiperRef = useRef();

<SwipeCards
          ref={swiperRef}
          cards={cards}
          renderCard={cardData => (
            <Card data={cardData} swiperRef={swiperRef} />
          )}
          keyExtractor={cardData => String(cardData.text)}
        />
    swiperRef is undefined.

    swiperRef.current is also undefined

But if I swipe on the card once then swiperRef.current.swipeNope() works.

b-hexsoul commented 2 years ago

Any progress on this? Gotta love how many open issues this package has...

chandrabuw commented 2 years ago

use this and its work

const useSwiper = useRef();
const handleOnSwipedLeft = () => useSwiper.current.swipeLeft();
const handleOnSwipedTop = () => useSwiper.swipeTop();
const handleOnSwipedRight = () => useSwiper.current.swipeRight();
Riaz5687 commented 2 years ago

const handleOnSwipedLeft = () => useSwiper.current.swipeLeft(); const handleOnSwipedTop = () => useSwiper.swipeTop(); const handleOnSwipedRight = () => useSwiper.current.swipeRight();

this work for me. thank you