react-native-card-stack-swiper icon indicating copy to clipboard operation
react-native-card-stack-swiper copied to clipboard

states not updating inside card

Open mitesh-db opened this issue 5 years ago • 5 comments

Hello @lhandel , I really appreciate your work, but I'm having one issue when I update some states it is NOT being updated inside card.

Can you please guide me here

For example, I have one state loading: true in constructor, In componentDidMount I set to loading: false, But this.state.loading never gets updated value and always returns <Loader> (It is custom component - Which shows loader)

following is my code:

<CardStack
        style={styles.cardstack}
        verticalSwipe={false}
        ref={(swiper) => {
          this.swiper = swiper;
        }}
        renderNoMoreCards={() => (
          <Text style={{fontWeight: '700', fontSize: 18, color: 'gray'}}>
            No more cards :(
          </Text>
        )}
        onSwiped={() => console.log('onSwiped')}
        onSwipedLeft={() => console.log('onSwipedLeft')}>
        <Card style={styles.card}>
        {this.state.loading ? <Loader /> : null}

        </Card>
</CardStack>

Here loader always keep loading even if state changes to false

mitesh-db avatar Nov 02 '20 11:11 mitesh-db

Also if I set something like this inside <Card>,

<Text style={styles.name_title}>{this.state.f_name}</Text>

f_name never gets updated value

mitesh-db avatar Nov 02 '20 11:11 mitesh-db

@mitjnextt did you ever solve this?

ethans333 avatar Dec 13 '20 18:12 ethans333

@ethans333 I found using this.swiper.initDeck(); right after setState will reload the card. But it have another issue it will bring you all the card that was swiped/removed from the stack.

mitesh-db avatar Jan 01 '21 05:01 mitesh-db

It is because CardStack is comparing the keys of its children (Card) and it only updates the state if they are different. Look into componentDidUpdate in CardStack. Since you only have one Card i guess you can just add 'isLoading' as the key which would make the key change when isLoading changes resulting in a re-render of the Card component.

Coci0AlexMeew avatar Jan 28 '21 14:01 Coci0AlexMeew

same issue can you please give more details...

sanketk478 avatar Dec 15 '21 09:12 sanketk478