From 0ca6c136e398b4719ffbe24ee9c5c27077edc429 Mon Sep 17 00:00:00 2001 From: popovspiridon99 Date: Thu, 6 Mar 2025 15:37:49 +0900 Subject: [PATCH] ObjectTree: Memoize ObjectList --- client/src/components/Tree/ObjectTree.tsx | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/client/src/components/Tree/ObjectTree.tsx b/client/src/components/Tree/ObjectTree.tsx index 9224e9d..4109f00 100644 --- a/client/src/components/Tree/ObjectTree.tsx +++ b/client/src/components/Tree/ObjectTree.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import useSWR from 'swr' import { fetcher } from '../../http/axiosInstance' import { BASE_URL } from '../../constants' @@ -118,15 +118,25 @@ const ObjectList = ({ } ) + const navLinks = useMemo(() => ( + Array.isArray(data) ? data.map((type) => ( + setCurrentObjectId(map_id, type.object_id)} /> + )) : null + ), [data, map_id]); + return ( - { - setSelectedObjectType(map_id, id) - }} rightSection={} p={0} label={`${label} ${count ? `(${count})` : ''}`}> - {Array.isArray(data) && data.map((type) => ( - setCurrentObjectId(map_id, type.object_id)} /> - ))} + setSelectedObjectType(map_id, id)} rightSection={} p={0} label={`${label} ${count ? `(${count})` : ''}`}> + {navLinks} - ) + ); + + // return ( + // { setSelectedObjectType(map_id, id) }} rightSection={} p={0} label={`${label} ${count ? `(${count})` : ''}`}> + // {Array.isArray(data) && data.map((type) => ( + // setCurrentObjectId(map_id, type.object_id)} /> + // ))} + // + // ) } export default ObjectTree \ No newline at end of file