Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

states not updating inside card #76

Open
mitesh-db opened this issue Nov 2, 2020 · 5 comments
Open

states not updating inside card #76

mitesh-db opened this issue Nov 2, 2020 · 5 comments

Comments

@mitesh-db
Copy link

mitesh-db commented Nov 2, 2020

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 (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
Copy link
Author

mitesh-db commented Nov 2, 2020

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

@ethans333
Copy link

@mitjnextt did you ever solve this?

@mitesh-db
Copy link
Author

mitesh-db commented Jan 1, 2021

@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.

@Coci0AlexMeew
Copy link

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.

@sanketk478
Copy link

same issue can you please give more details...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants