Example right here: when clicking the up or downvote arrow, the UI reflects the vote immediately, even if the server hasn't successfully processed it yet. The vote will actually be rolled back with an error message if the server fails.
xxxxxxxxxx
const ITEM_HEIGHT = 65; // fixed height of item component
const getItemLayout = (data, index) => {
return {
length: ITEM_HEIGHT,
offset: ITEM_HEIGHT * index,
index,
};
};
return (
<Flatlist
data={data}
renderItem={renderItem}
getItemLayout={getItemLayout}
keyExtractor={keyExtractor}
/>
);