An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: Add useSearchParams hook to Chat component
Yoshiki Miuraed9a1533d656
diff --git a/components/chat.tsx b/components/chat.tsxindex 62956602..64c28567 100644--- a/components/chat.tsx+++ b/components/chat.tsx@@ -1,7 +1,7 @@'use client'import { useEffect } from 'react'-import { usePathname } from 'next/navigation'+import { usePathname, useSearchParams } from 'next/navigation'import { ChatPanel } from './chat-panel'import { ChatMessages } from './chat-messages'import { useUIState } from 'ai/rsc'@@ -13,16 +13,17 @@ type ChatProps = {export function Chat({ id, query }: ChatProps) {const path = usePathname()+ const searchParams = useSearchParams()const [messages] = useUIState()useEffect(() => {if ((!path.includes('search') && messages.length === 1) ||- (path.includes('/search?q=') && query && messages.length === 1)+ (searchParams.get('q') && messages.length === 1)) {window.history.replaceState({}, '', `/search/${id}`)}- }, [id, path, messages, query])+ }, [id, path, messages, query, searchParams])return (<div className="px-8 sm:px-12 pt-12 md:pt-14 pb-14 md:pb-24 max-w-3xl mx-auto flex flex-col space-y-3 md:space-y-4">diff --git a/components/search-related.tsx b/components/search-related.tsxindex 554b9218..ca44bfcb 100644--- a/components/search-related.tsx+++ b/components/search-related.tsx@@ -28,7 +28,6 @@ export const SearchRelated: React.FC<SearchRelatedProps> = ({const [related, setRelated] = useState<PartialRelated>()useEffect(() => {- console.log('data', data)if (!data) returnsetRelated(data)}, [data])