ObjectTree: Memoize ObjectList
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import { fetcher } from '../../http/axiosInstance'
|
import { fetcher } from '../../http/axiosInstance'
|
||||||
import { BASE_URL } from '../../constants'
|
import { BASE_URL } from '../../constants'
|
||||||
@ -118,15 +118,25 @@ const ObjectList = ({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
const navLinks = useMemo(() => (
|
||||||
<NavLink onClick={() => {
|
Array.isArray(data) ? data.map((type) => (
|
||||||
setSelectedObjectType(map_id, id)
|
|
||||||
}} rightSection={<IconChevronDown size={14} />} p={0} label={`${label} ${count ? `(${count})` : ''}`}>
|
|
||||||
{Array.isArray(data) && data.map((type) => (
|
|
||||||
<NavLink key={type.object_id} label={type.caption ? type.caption : 'Без названия'} p={0} onClick={() => setCurrentObjectId(map_id, type.object_id)} />
|
<NavLink key={type.object_id} label={type.caption ? type.caption : 'Без названия'} p={0} onClick={() => setCurrentObjectId(map_id, type.object_id)} />
|
||||||
))}
|
)) : null
|
||||||
|
), [data, map_id]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<NavLink onClick={() => setSelectedObjectType(map_id, id)} rightSection={<IconChevronDown size={14} />} p={0} label={`${label} ${count ? `(${count})` : ''}`}>
|
||||||
|
{navLinks}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
)
|
);
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <NavLink onClick={() => { setSelectedObjectType(map_id, id) }} rightSection={<IconChevronDown size={14} />} p={0} label={`${label} ${count ? `(${count})` : ''}`}>
|
||||||
|
// {Array.isArray(data) && data.map((type) => (
|
||||||
|
// <NavLink key={type.object_id} label={type.caption ? type.caption : 'Без названия'} p={0} onClick={() => setCurrentObjectId(map_id, type.object_id)} />
|
||||||
|
// ))}
|
||||||
|
// </NavLink>
|
||||||
|
// )
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ObjectTree
|
export default ObjectTree
|
Reference in New Issue
Block a user