1

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.

Any help would be much appreciated

running test on codesandbox: test

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;
Erez
  • 6,405
  • 14
  • 70
  • 124
  • Unfortunately the Swiper will not know whether to rerender itself if a state changes inside unless you swipe the card around which will rerender the card with the correct state. Have you tried this solution? https://github.com/alexbrillant/react-native-deck-swiper/issues/153 – caslawter Oct 17 '22 at 01:07

0 Answers0