@@ -146,25 +146,33 @@ export const InteractiveGraphics = ({
146146 size ,
147147 )
148148
149- const filteredLines = useMemo (
150- ( ) => graphics . lines ?. filter ( filterLines ) || [ ] ,
151- [ graphics . lines , filterLines ] ,
152- )
149+ const filteredLines = useMemo ( ( ) => {
150+ if ( ! graphics . lines ) return [ ]
151+ return graphics . lines
152+ . map ( ( line , index ) => ( { line, originalIndex : index } ) )
153+ . filter ( ( item ) => filterLines ( item . line ) )
154+ } , [ graphics . lines , filterLines ] )
153155
154- const filteredPoints = useMemo (
155- ( ) => graphics . points ?. filter ( filterPoints ) || [ ] ,
156- [ graphics . points , filterPoints ] ,
157- )
156+ const filteredPoints = useMemo ( ( ) => {
157+ if ( ! graphics . points ) return [ ]
158+ return graphics . points
159+ . map ( ( point , index ) => ( { point, originalIndex : index } ) )
160+ . filter ( ( item ) => filterPoints ( item . point ) )
161+ } , [ graphics . points , filterPoints ] )
158162
159- const filteredRects = useMemo (
160- ( ) => graphics . rects ?. filter ( filterRects ) || [ ] ,
161- [ graphics . rects , filterRects ] ,
162- )
163+ const filteredRects = useMemo ( ( ) => {
164+ if ( ! graphics . rects ) return [ ]
165+ return graphics . rects
166+ . map ( ( rect , index ) => ( { rect, originalIndex : index } ) )
167+ . filter ( ( item ) => filterRects ( item . rect ) )
168+ } , [ graphics . rects , filterRects ] )
163169
164- const filteredCircles = useMemo (
165- ( ) => graphics . circles ?. filter ( filterCircles ) || [ ] ,
166- [ graphics . circles , filterCircles ] ,
167- )
170+ const filteredCircles = useMemo ( ( ) => {
171+ if ( ! graphics . circles ) return [ ]
172+ return graphics . circles
173+ . map ( ( circle , index ) => ( { circle, originalIndex : index } ) )
174+ . filter ( ( item ) => filterCircles ( item . circle ) )
175+ } , [ graphics . circles , filterCircles ] )
168176
169177 const visibleObjectCount = useMemo (
170178 ( ) =>
@@ -303,35 +311,35 @@ export const InteractiveGraphics = ({
303311 } }
304312 >
305313 < DimensionOverlay transform = { realToScreen } >
306- { displayedLines . map ( ( line ) => (
314+ { displayedLines . map ( ( { line, originalIndex } ) => (
307315 < Line
308- key = { `line-${ graphics . lines ! . indexOf ( line ) } ` }
316+ key = { `line-${ originalIndex } ` }
309317 line = { line }
310- index = { graphics . lines ! . indexOf ( line ) }
318+ index = { originalIndex }
311319 interactiveState = { interactiveState }
312320 />
313321 ) ) }
314- { displayedRects . map ( ( rect ) => (
322+ { displayedRects . map ( ( { rect, originalIndex } ) => (
315323 < Rect
316- key = { `rect-${ graphics . rects ! . indexOf ( rect ) } ` }
324+ key = { `rect-${ originalIndex } ` }
317325 rect = { rect }
318- index = { graphics . rects ! . indexOf ( rect ) }
326+ index = { originalIndex }
319327 interactiveState = { interactiveState }
320328 />
321329 ) ) }
322- { displayedPoints . map ( ( point ) => (
330+ { displayedPoints . map ( ( { point, originalIndex } ) => (
323331 < Point
324- key = { `point-${ graphics . points ! . indexOf ( point ) } ` }
332+ key = { `point-${ originalIndex } ` }
325333 point = { point }
326- index = { graphics . points ! . indexOf ( point ) }
334+ index = { originalIndex }
327335 interactiveState = { interactiveState }
328336 />
329337 ) ) }
330- { displayedCircles . map ( ( circle ) => (
338+ { displayedCircles . map ( ( { circle, originalIndex } ) => (
331339 < Circle
332- key = { `circle-${ graphics . circles ! . indexOf ( circle ) } ` }
340+ key = { `circle-${ originalIndex } ` }
333341 circle = { circle }
334- index = { graphics . circles ! . indexOf ( circle ) }
342+ index = { originalIndex }
335343 interactiveState = { interactiveState }
336344 />
337345 ) ) }
0 commit comments