Skip to content

Commit 858fdd5

Browse files
authored
Merge pull request #437 from iKrushYou/master
Provide clarity on necessity of key property in the data array
2 parents b870524 + 1f52c60 commit 858fdd5

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ The application under ./SwipeListExample will produce the above example. To run
5959
```javascript
6060
import { SwipeListView } from 'react-native-swipe-list-view';
6161
62+
//... note: your data array objects MUST contain a key property
63+
// or you must pass a keyExtractor to the SwipeListView to ensure proper functionality
64+
// see: https://reactnative.dev/docs/flatlist#keyextractor
65+
66+
this.state.listViewData = Array(20)
67+
.fill("")
68+
.map((_, i) => ({ key: `${i}`, text: `item #${i}` }));
69+
70+
//...
6271
render() {
6372
return (
6473
<SwipeListView

components/SwipeListView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ SwipeListView.propTypes = {
654654
* Use Animated.Flatlist or Animated.Sectionlist
655655
*/
656656
useAnimatedList: PropTypes.bool,
657+
/**
658+
* keyExtractor: function to generate key value for each row in the list
659+
*/
660+
keyExtractor: PropTypes.func,
657661
};
658662

659663
SwipeListView.defaultProps = {

docs/SwipeListView.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# `<SwipeListView />` API
23

34
A List that renders `<SwipeRow />`s
@@ -6,6 +7,7 @@ A List that renders `<SwipeRow />`s
67

78
| Prop | Notes | Type | Signature (func) | Default |
89
| --- | --- | --- | --- | --- |
10+
| `data` | List of objects to be passed into the `renderItem` and `renderHiddenItem` functions. Each item must include a unique `key` property or `keyExtractor` must be implemented to ensure full functionality. | `array` ||
911
| `useSectionList` | Render list using React Native's `SectionList` | `bool` | | `false` |
1012
| `renderItem` | How to render a row in a FlatList. Should return a valid React Element. | `func` | `{ rowData: any, rowMap: { string: SwipeRowRef } } : ReactElement` |
1113
| `renderHiddenItem` | How to render a hidden row in a FlatList (renders behind the row). Should return a valid React Element. This is required unless `renderItem` returns a `<SwipeRow>` (see [Per Row Behavior](https://github.com/jemise111/react-native-swipe-list-view/blob/master/docs/per-row-behavior.md)). | `func` | `{ rowData: any, rowMap: { string: SwipeRowRef } } : ReactElement` |
@@ -60,3 +62,5 @@ A List that renders `<SwipeRow />`s
6062
| `shouldItemUpdate` | Callback to determine whether component should update | `func` | `{ currentItem: any, newItem: any }` |
6163
| `useNativeDriver` | useNativeDriver: `true` for all animations | `bool` | `true` |
6264
| `useAnimatedList` | Use Animated.Flatlist or Animated.Sectionlist | `bool` | `false` |
65+
66+
See [FlatList](https://reactnative.dev/docs/flatlist) for all other inherited props

0 commit comments

Comments
 (0)