Skip to content

Commit 7d5d64e

Browse files
committed
feat: optimize filtered hits calculation using useMemo in LibraryContent
1 parent 7c59886 commit 7d5d64e

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/library-authoring/LibraryContent.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react';
1+
import { useEffect, useMemo } from 'react';
22
import { LoadingSpinner } from '../generic/Loading';
33
import { useSearchContext } from '../search-manager';
44
import { NoComponents, NoSearchResults } from './EmptyStates';
@@ -50,9 +50,12 @@ const LibraryContent = ({ contentType = ContentType.home }: LibraryContentProps)
5050
* selection workflow when adding components to xblocks by choosing the whole collection in Collections tab.
5151
* Note: LibraryAuthoringPage.tsx has been modified to skip backend filtering for this purpose.
5252
*/
53-
const filteredHits = contentType === ContentType.collections
54-
? hits.filter((hit) => hit.type === 'collection')
55-
: hits;
53+
const filteredHits = useMemo(
54+
() => (contentType === ContentType.collections
55+
? hits.filter((hit) => hit.type === 'collection')
56+
: hits),
57+
[hits, contentType],
58+
);
5659

5760
useEffect(() => {
5861
if (usageKey) {

0 commit comments

Comments
 (0)