From bd13a97d0f2af258826fd101e23d346d3cba4008 Mon Sep 17 00:00:00 2001 From: Sebastian-Webster Date: Sun, 18 Feb 2024 04:17:52 +1300 Subject: [PATCH] feat: allow for custom keyExtractor props in ItemAutoList --- components/ItemAutoList.js | 6 ++++-- screens/CategoryMemberViewPage.js | 1 + screens/PollVoteViewPage.js | 1 + screens/VotesViewPage.js | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/ItemAutoList.js b/components/ItemAutoList.js index e785bce..7905004 100644 --- a/components/ItemAutoList.js +++ b/components/ItemAutoList.js @@ -8,7 +8,9 @@ import { ServerUrlContext } from "./ServerUrlContext"; import ParseErrorMessage from "./ParseErrorMessage"; import Ionicons from 'react-native-vector-icons/Ionicons'; -export default function ItemAutoList({noItemsFoundText, centreIfNoItems, url, extraPOSTData = {}, DisplayComponent, extraProps = {}, state, dispatch, noMoreItemsText}) { +const defaultKeyExtractor = item => item._id + +export default function ItemAutoList({noItemsFoundText, centreIfNoItems, url, extraPOSTData = {}, DisplayComponent, extraProps = {}, state, dispatch, noMoreItemsText, keyExtractor = defaultKeyExtractor}) { const {colors} = useTheme(); const {serverUrl} = useContext(ServerUrlContext); const AbortControllerRef = useRef(new AbortController()); @@ -82,7 +84,7 @@ export default function ItemAutoList({noItemsFoundText, centreIfNoItems, url, ex /> } renderItem={({item, index}) => } - keyExtractor={item => item._id} + keyExtractor={keyExtractor} onEndReachedThreshold={3} onEndReached = {({distanceFromEnd})=>{ if (distanceFromEnd > 0) { diff --git a/screens/CategoryMemberViewPage.js b/screens/CategoryMemberViewPage.js index 4dc591f..0148a97 100644 --- a/screens/CategoryMemberViewPage.js +++ b/screens/CategoryMemberViewPage.js @@ -29,6 +29,7 @@ export default function CategoryMemberViewPage({route}) { DisplayComponent={UserItem} state={state} dispatch={dispatch} + keyExtractor={(item) => item.secondId} /> ) diff --git a/screens/PollVoteViewPage.js b/screens/PollVoteViewPage.js index 63dd76b..e0d8bce 100644 --- a/screens/PollVoteViewPage.js +++ b/screens/PollVoteViewPage.js @@ -31,6 +31,7 @@ export default function PollVoteViewPage({route}) { state={state} dispatch={dispatch} noMoreItemsText="No more votes left." + keyExtractor={(item) => item.secondId} /> ) diff --git a/screens/VotesViewPage.js b/screens/VotesViewPage.js index 0746227..8c7b41f 100644 --- a/screens/VotesViewPage.js +++ b/screens/VotesViewPage.js @@ -45,6 +45,7 @@ export default function VotesViewPage({route}) { } } }} + keyExtractor={(item) => item.secondId} noMoreItemsText="No more items left" />