ListItem Switch Component doesn't stay switched on
See original GitHub issueFrom the Snack that was referenced in #256, I’m seeing the switch reverting to off each time it is switched on.
Adding switchButton to my code and testing in the iOS simulator reproduced the same issue.
Steps to reproduce:
- Open https://snack.expo.io/SJPQNScUZ. Turn switch in row 2 on.
- Switch should stay on
- Switch turns off
Using RNE version 0.18.4
<List>
<FlatList style={{width: viewportWidth}}
data={this.state.contacts}
ListHeaderComponent={this.renderContactListHeader}
renderItem = {({item}) => renderListItem(item)}
keyExtractor={item => item.id}
/>
</List>
renderListItem = (item) => {
const li = <ListItem
hideChevron
switchButton
title={`${item.firstName} ${item.lastName}`}
subtitle={item.emails[0].email}
onPress={() => handleContactPress(item)}
/>;
return li;
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
React Native elements list item switch not working
To fix this, you need to hold the switched value for each ListItem somewhere; probably the most straightforward would be in what you...
Read more >Switch - React Native
This is a controlled component that requires an onValueChange callback that updates the value prop in order for the component to reflect user ......
Read more >Create interactive components with variants - Figma Help Center
Create variant interactions · Select the starting variant for the interaction from within the component set. · Navigate to the Prototype tab of...
Read more >React key attribute: best practices for performant lists
Looking into how React "key" attribute works, how to use it correctly, how to improve performance of lists with it, and why array...
Read more >8 common React error messages and how to address them
This is caused by a state update that is dependent on an async request. The async request starts somewhere in the lifecycle of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As it is specified in the React Native Switch documentation, the
Switch
component is a controlled component. This means that you have to handle by yourself the state of the component to reflect user actions, by using theonValueChange
callback and updating an internal state. You’ll then use this state as thevalue
props of theSwitch
component 🙌 Thanks for the Snack @jnpdx !Sorry for the delay - I’m just getting back to this functionality in my app now. Appreciate the info @jnpdx. The example you provided works for me.