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

How to prevent re-rendering of FlatList #16240

Closed
pgwzzz opened this issue Oct 7, 2017 · 4 comments
Closed

How to prevent re-rendering of FlatList #16240

pgwzzz opened this issue Oct 7, 2017 · 4 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@pgwzzz
Copy link

pgwzzz commented Oct 7, 2017

Hello.

I'm implementing chatting with FlatList.

Every time there is a new chat message detected, I do the following.

let newItem = {...}; // read a new chat message from server
let nextFlatListData = this.state.flatListData.slice(0); // clone the chat list
nextFlatListData.push(newItem); // add the new chat to the list
this.setState({flatListData: nextFlatListData}); // update FlatList

It seems that it re-renders every row.

I just need the row for newItem is rendered and the others are NOT re-rendered.

Thank you very much.

@PatNeedham
Copy link

@pgwzzz can you share the renderItem prop you're using for your Flatlist? Including a key property as part of all the objects in the array you use for the FlatList (or a keyExtractor prop) is necessary to prevent re-renders.

@marcesengel
Copy link
Contributor

Also you could try using a PureComponent or implement an own shouldComponentUpdate for your items. Your old components will be passed the same props again (if your old messages don't change), so they won't rerender if you use a PureComponent.

@pull-bot
Copy link

@facebook-github-bot no-template

@facebook-github-bot
Copy link
Contributor

Hey, thanks for reporting this issue! It looks like your description is missing some necessary information, or the list of reproduction steps is not complete. Can you please add all the details specified in the Issue Template? This is necessary for people to be able to understand and reproduce the issue being reported. I am going to close this, but feel free to open a new issue with the additional information provided. Thanks! See "What to Expect from Maintainers" to learn more.

@facebook-github-bot facebook-github-bot added the Ran Commands One of our bots successfully processed a command. label Oct 10, 2017
@facebook facebook locked as resolved and limited conversation to collaborators Oct 10, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants