Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions app/hooks/use-search-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ interface SearchContextValue {
onClose: () => void;
onOpenChange: (open: boolean) => void;
toggle: () => void;
open: () => void;
close: () => void;
setOpen: (open: boolean) => void;
}

const SearchContext = createContext<SearchContextValue | undefined>(undefined);
Expand All @@ -20,13 +23,18 @@ export function SearchProvider({ children }: { children: ReactNode }) {
const onOpenChange = useCallback((open: boolean) => setIsOpen(open), []);
const toggle = useCallback(() => setIsOpen((prev) => !prev), []);

// Performance optimization: Include HeroUI compatibility aliases directly in the
// context value memoization to prevent allocating a new wrapper object on every call to useSearchState.
const value = useMemo(
() => ({
isOpen,
onOpen,
onClose,
onOpenChange,
toggle,
open: onOpen,
close: onClose,
setOpen: onOpenChange,
}),
[isOpen, onOpen, onClose, onOpenChange, toggle]
);
Expand All @@ -40,13 +48,5 @@ export function useSearchState() {
throw new Error("useSearchState must be used within a SearchProvider");
}

return useMemo(
() => ({
...context,
open: context.onOpen,
close: context.onClose,
setOpen: context.onOpenChange,
}),
[context]
);
return context;
}