-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
FlatList execute renderItem 2 or 3 times per FlatList render? #20922
Comments
Any one have the same question? |
related to #14528 |
Yes, this bug exists in React Native 0.55.4 as well, One of the things you can do to prevent this behaviour is wrap your Render Item this way
Even a shouldComponentUpdate should work, BTW I use mobx and I annotate my component with @observer which takes care of the shouldComponentUpdate for me. This solves the issue, but your render Item is still fired multiple times, only advantage is that your actual Component will not be re-rendered for those extra calls to renderItem, due to PureComponent implementation. Can anyone confirm if renderItem is fired multiple times for previously rendered rows intentionally or is this a bug. Forgive me for I really do not know how FlatList is implemented from the ground up, but I am guessing, the renderItem callback should only be called once for each item. |
I recreated the issue in this snack. https://snack.expo.io/B1KoX-EUN - I confirmed you can use shouldComponentUpdate(nextProps, nextState) to diff this.state or this.props and return true/false - https://reactjs.org/docs/react-component.html#shouldcomponentupdate docs say this callback should be used only for optimization which is what we're doing here. |
As @geeklevel1000 pointed out, I don't think this is really an issue. The number of times the items are actually rendered is implementation detail of FlatList. As long as you don't have any performance problems, you should not be worried. The same code runs inside Facebook applications where they don't have major problems out of it. As others suggested above and in another issue (#14528 (comment)), use |
I have data
how can i render this type of data in Flatlist
|
We're using an environment where JavaScript has no JIT, so the multiple renderItem calls per item are definitely causing a performance hit. |
Environment
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
Memory: 70.11 MB / 8.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 9.5.0 - /usr/local/bin/node
Yarn: 1.9.4 - ~/.yarn/bin/yarn
npm: 5.6.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.2, macOS 10.13, tvOS 11.2, watchOS 4.2
Android SDK:
Build Tools: 23.0.1, 23.0.2, 23.0.3, 24.0.1, 24.0.2, 24.0.3, 25.0.0, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.3
API Levels: 21, 22, 23, 24, 25, 26, 27
IDEs:
Android Studio: 3.1 AI-173.4819257
Xcode: 9.2/9C40b - /usr/bin/xcodebuild
npmPackages:
react: 16.4.1 => 16.4.1
react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
react-native-cli: 2.0.1
Description
FlatList execute renderItem 2 or 3 times per FlatList render?
if the data length > 10 ,renderItem may execute 3 times else 2 times, why?
Is there something wrong in my code?
Reproducible Demo
logs
code
The text was updated successfully, but these errors were encountered: