Skip to content

Commit fb424c1

Browse files
committed
fix : Issue#754
1 parent 109c526 commit fb424c1

File tree

2 files changed

+7952
-4
lines changed

2 files changed

+7952
-4
lines changed

apps/web/components/ContentSearch.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import { useEffect, useRef, useState, useDeferredValue } from "react";
2+
import { useEffect, useRef, useState, useDeferredValue, useMemo } from "react";
33
import Link from "next/link";
44
import { Cross2Icon, MagnifyingGlassIcon } from "@radix-ui/react-icons";
55
import { Dialog, DialogClose, DialogContent, Input, Card, CardDescription, CardHeader, CardTitle } from "@repo/ui";
@@ -45,11 +45,15 @@ export function ContentSearch({ tracks }: { tracks: TrackPros[] }) {
4545
});
4646
setAllTracks(updatedTracks);
4747
}, []);
48-
useEffect(() => {
49-
const fuse = new Fuse(allTracks, {
48+
49+
// Memoize to avoid unnecessary re-computation
50+
const fuse = useMemo(() => {
51+
return new Fuse(allTracks, {
5052
keys: ["payload.problemTitle"],
5153
});
54+
}, [allTracks]);
5255

56+
useEffect(() => {
5357
async function fetchSearchResults() {
5458
if (deferredInput.length > 0) {
5559
/* const data = await getSearchResults(deferredInput); */
@@ -61,7 +65,7 @@ export function ContentSearch({ tracks }: { tracks: TrackPros[] }) {
6165
}
6266
}
6367
fetchSearchResults();
64-
}, [deferredInput]);
68+
}, [deferredInput , fuse]);
6569

6670
useEffect(() => {
6771
const handleKeyPress = (event: KeyboardEvent) => {

0 commit comments

Comments
 (0)