Skip to content

Commit

Permalink
Fix infinite loop location api (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-lin-bbpos authored Aug 15, 2024
1 parent c98244a commit 6e63892
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dev-app/src/screens/LocationListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function LocationListScreen() {
const { params } = useRoute<RouteProp<RouteParamList, 'LocationList'>>();

const { getLocations, loading } = useStripeTerminal();
const [list, setList] = useState<Location[]>([]);
const [list, setList] = useState<Location[]>(cachedLocations);
const dummyLocations: Location[] = [
{ id: 'ABCD', displayName: 'Bad Location', livemode: false },
{
Expand All @@ -34,18 +34,21 @@ export default function LocationListScreen() {
},
];

useEffect(() => {
if (list != null && list.length != 0) {
setCachedLocations(list);
}
}, [list, setCachedLocations]);

useEffect(() => {
async function init() {
const { locations } = await getLocations({ limit: 20 });
if (locations) {
setList(locations);
setCachedLocations(locations);
} else {
setList(cachedLocations);
}
}
init();
}, [getLocations, setCachedLocations, cachedLocations]);
}, [getLocations]);

const renderItem = (item: Location) => (
<ListItem
Expand Down

0 comments on commit 6e63892

Please sign in to comment.