From 304c4d38b736bec3e64e85e331ffbd615c1a2d25 Mon Sep 17 00:00:00 2001 From: evlist Date: Tue, 11 Oct 2022 14:15:46 +0200 Subject: [PATCH] Reinitializing noteIndex when fetching new notes (to avoid out of length indexes). --- src/components/map/LocationInfo.tsx | 72 +++++++++++++++-------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/src/components/map/LocationInfo.tsx b/src/components/map/LocationInfo.tsx index ec953a7..3559635 100644 --- a/src/components/map/LocationInfo.tsx +++ b/src/components/map/LocationInfo.tsx @@ -77,6 +77,7 @@ const LocationInfo: React.FC<{}> = () => { const findNotes = async () => { setNotes(undefined); + setNoteIndex(0); const metresPerDegree = 111111 * Math.cos((scope.center.lat * Math.PI) / 180); const deltaDegrees = 2000 / metresPerDegree; @@ -249,41 +250,42 @@ const LocationInfo: React.FC<{}> = () => { /> - {notes.features[noteIndex].properties.comments.map( - (comment: any, index: number) => ( - - - - - - ) - )} + {noteIndex < notes.features.length && + notes.features[noteIndex].properties.comments.map( + (comment: any, index: number) => ( + + + + + + ) + )}