diff --git a/apps/web/src/components/action-bar.tsx b/apps/web/src/components/action-bar.tsx index 5f86014..8aeea6d 100644 --- a/apps/web/src/components/action-bar.tsx +++ b/apps/web/src/components/action-bar.tsx @@ -9,7 +9,12 @@ import { Plus, Users, } from "lucide-react"; -import { type FormEvent, type RefObject, useState } from "react"; +import { + type FormEvent, + type RefObject, + useDeferredValue, + useState, +} from "react"; import type { SearchResult } from "../hooks/use-bestiary.js"; import { cn } from "../lib/utils.js"; import { D20Icon } from "./d20-icon.js"; @@ -270,6 +275,8 @@ export function ActionBar({ const [nameInput, setNameInput] = useState(""); const [suggestions, setSuggestions] = useState([]); const [pcMatches, setPcMatches] = useState([]); + const deferredSuggestions = useDeferredValue(suggestions); + const deferredPcMatches = useDeferredValue(pcMatches); const [suggestionIndex, setSuggestionIndex] = useState(-1); const [queued, setQueued] = useState(null); const [customInit, setCustomInit] = useState(""); @@ -394,7 +401,8 @@ export function ActionBar({ } }; - const hasSuggestions = suggestions.length > 0 || pcMatches.length > 0; + const hasSuggestions = + deferredSuggestions.length > 0 || deferredPcMatches.length > 0; const handleKeyDown = (e: React.KeyboardEvent) => { if (!hasSuggestions) return; @@ -495,10 +503,10 @@ export function ActionBar({ )} )} - {browseMode && suggestions.length > 0 && ( + {browseMode && deferredSuggestions.length > 0 && (
    - {suggestions.map((result, i) => ( + {deferredSuggestions.map((result, i) => (