Skip to content

Commit

Permalink
Add function based components example for Flat list optimisation (#2955)
Browse files Browse the repository at this point in the history
  • Loading branch information
DibyajyotiMishra committed Feb 4, 2022
1 parent b675091 commit ba50a5a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/optimizing-flatlist-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: optimizing-flatlist-configuration
title: Optimizing Flatlist Configuration
---

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants';

## Terms

- **VirtualizedList:** The component behind `FlatList` (React Native's implementation of the [`Virtual List`](https://bvaughn.github.io/react-virtualized/#/components/List) concept.)
Expand Down Expand Up @@ -123,6 +125,9 @@ You can also use a `key` prop in your item component.

Move out the `renderItem` function to the outside of render function, so it won't recreate itself each time render function called.

<Tabs groupId="syntax" defaultValue={constants.defaultSyntax} values={constants.syntax}>
<TabItem value="classical">

```jsx
renderItem = ({ item }) => (<View key={item.key}><Text>{item.title}</Text></View>);

Expand All @@ -136,4 +141,26 @@ render(){

// ...
}

```

</TabItem>
<TabItem value="functional">

```jsx
const renderItem = ({ item }) => (
<View key={item.key}>
<Text>{item.title}</Text>
</View>
);

return (
// ...

<FlatList data={items} renderItem={renderItem} />;
// ...
);
```

</TabItem>
</Tabs>

0 comments on commit ba50a5a

Please sign in to comment.