Abhirup Mukherjee
Abhirup Mukherjee

Reputation: 499

How can I refresh a particular row on a flatlist in react-native?

I am trying to refresh a particular cell/row in a flatlist. How can i just refresh a single cell when data is loaded. And after refreshing display the data?

Is it possible to refresh a particular row in a view of react-native? For e.g i'm displaying images in a row nested inside <View/>.

Upvotes: 2

Views: 1670

Answers (2)

wicky
wicky

Reputation: 978

I believe you might be looking for React.PureComponent which implements a shallow prop and state comparison to decide if rerender is needed. You can achieve this with shouldComponentUpdate() on React.Component too.

There is already an example in FlatList's docs that demonstrate how you can use PureComponent to render your list, just scroll down abit and look for the "more complex example" :)

If you prefer to use a Functional Component instead of a Class Component, checkout React.memo, which is similar to React.PureComponent but for Functional Components. Hope it helps.

Upvotes: 0

abhinandan sharma
abhinandan sharma

Reputation: 883

You can try extraData in FlatList to update a particular item in flatlist. When state is changed the flatlist will rerender.

<FlatList

    extraData={this.state}
    data={this.state.asPerCode}
    renderItem={this.renderPost}

/> 

you can check about extra data in react native flatlist docs.

Hope it helps!

Upvotes: 2

Related Questions