Skip to content

Commit

Permalink
wrap doSearch with useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
heweikang committed Aug 20, 2024
1 parent 7ce2e8f commit fcd55df
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/components/search-chat.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from "react";
import { useState, useEffect, useRef, useCallback } from "react";
import { ErrorBoundary } from "./error";
import styles from "./mask.module.scss";
import { useNavigate } from "react-router-dom";
Expand Down Expand Up @@ -27,7 +27,7 @@ export function SearchChatPage() {

const previousValueRef = useRef<string>("");
const searchInputRef = useRef<HTMLInputElement>(null);
const doSearch = (text: string) => {
const doSearch = useCallback((text: string) => {
const lowerCaseText = text.toLowerCase();
const results: Item[] = [];

Expand Down Expand Up @@ -65,7 +65,7 @@ export function SearchChatPage() {
results.sort((a, b) => b.content.length - a.content.length);

return results;
};
}, []);

useEffect(() => {
const intervalId = setInterval(() => {
Expand Down

0 comments on commit fcd55df

Please sign in to comment.