react-native-deck-swiper icon indicating copy to clipboard operation
react-native-deck-swiper copied to clipboard

Content of card does not render when state changed

Open ErezBiren opened this issue 2 years ago • 2 comments

I did a simple example with TouchableOpacity that on press changes the count state from 1 to 2 and displays it as Text, but the new value is not rerendered.

https://codesandbox.io/s/runtime-forest-b5nqmc?file=/src/App.js

Any help would be much appreciated

import React, {useState} from 'react';
import {Text, View, TouchableOpacity} from 'react-native';
import Swiper from 'react-native-deck-swiper';

const App = () => {
  const [count,setCount] = useState(0);

  return (
    <Swiper
      cards={['a', 'b', 'c']}
      renderCard={() => {
        return (
          <View>
            <TouchableOpacity onPress={() => {
              setCount(2);
              console.log("Clicked");

            }} style={{ backgroundColor: 'yellow', width:60 }}>
            <Text>Increase</Text>
            </TouchableOpacity>

            <Text>{count}</Text>
           
          </View>);
      }}/>
            
  );
};

export default App;

ErezBiren avatar Oct 16 '22 21:10 ErezBiren

same issue

iyansr avatar Nov 07 '22 18:11 iyansr

You can assign a ref to the DeckSwiper and call ref.forceUpdate() accordingly to get around this.

YoussefHenna avatar May 09 '23 10:05 YoussefHenna