2

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/>.

Abhirup Mukherjee
  • 309
  • 1
  • 2
  • 18
  • It would help us a lot if you can show us code you currently have. It's also possible that this questions is a duplicate of https://stackoverflow.com/questions/1077041/refresh-image-with-a-new-one-at-the-same-url – Tyro Hunter Mar 25 '19 at 06:11

2 Answers2

2

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!

0

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.

wicky
  • 888
  • 6
  • 13