FlatList ScrollView Error on any State Change - Invariant Violation: Changing onViewableItemsChanged on the fly is not supported
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment: OS: macOS High Sierra 10.13.1 Node: 6.11.4 Yarn: 1.1.0 npm: 5.3.0 Watchman: Not Found Xcode: Xcode 9.2 Build version 9C40b Android Studio: 2.3 AI-162.4069837
Packages: (wanted => installed) react: 16.0.0 => 16.0.0 react-native: 0.51.0 => 0.51.0
Steps to Reproduce
- Please refer to snack
- Repo has also been uploaded at github
- Any state change produces an error when using
onViewableItemsChanged
- What does this error even mean?
Note: Placing the onViewableItemsChanged
function in a const
outside the render method also does not assist…
<FlatList
data={this.state.cardData}
horizontal={true}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
onViewableItemsChanged={(info) =>console.log(info)}
viewabilityConfig={{viewAreaCoveragePercentThreshold: 50}}
renderItem={({item}) =>
<View style={{width: width, borderColor: 'white', borderWidth: 20,}}>
<Text>Dogs and Cats</Text>
</View>
}
/>
Expected Behavior
I’m not sure why this is happening. I would like to know if this is a bug with the current release, of if I’m doing something wrong.
Should users be using a separate workaround (ie. using onScroll
rather than onViewableItemsChanged
for information on scroll Position?
What does this error even mean?
Actual Behavior
Error
Reproducible Demo
Issue Analytics
- State:
- Created 6 years ago
- Comments:11
Top Results From Across the Web
react native - FlatList ScrollView Error on any State Change
The error "Changing onViewableItemsChanged on the fly is not supported" occurs because when you update the state, you are creating a new ...
Read more >Changing onViewableItemsChanged on the fly is not supported
This method still has no response in my project. Although no error is reported, onViewableItemsChanged will not be executed. @omitchen I had the ......
Read more >React-native – FlatList ScrollView Error on any State Change ...
React-native – FlatList ScrollView Error on any State Change – Invariant Violation: Changing onViewableItemsChanged on the fly is not supported.
Read more >Changing onViewableItems on the fly is not supported - Reddit
Hi everybody, I want to use onViewableItemsChanged prop on FlatList to check if last item on FlatList is viewable on the screen but...
Read more >Flatlist Scrollview Error On Any State Change - Invariant ...
The error Changing onViewableItemsChanged on the fly is not supported occurs because when you update the state you are creating a new onViewableItemsChanged....
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 FreeTop 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
Top GitHub Comments
@njho I believe you’ll need to set both the
onViewableItemsChanged
and theviewabilityConfig
props as class properties, rather than inside therender()
method.E.g
Working Snack example: https://snack.expo.io/rJp1MLd7f
@njho Both the
viewabilityConfig
prop and theonViewableItemsChanged
are compared with their previous values in thecomponentWillReceiveProps()
method of the FlatList component. This is done using the triple equals symbol.Since you are using an inline arrow function and an inline object literal, these are re-created on each render. This means that the exception will be thrown on each render since the reference of the function or object is different each time.
I don’t know what purpose the checks serve, I just took a peek at the source code haha.
https://github.com/facebook/react-native/blob/master/Libraries/Lists/FlatList.js#L430-L451