Skip to content

An AI-powered search engine with a generative UI

fix: Pass query parameter to Chat component in search page

Yoshiki Miura79f0e2af7c08
diff --git a/app/search/page.tsx b/app/search/page.tsx
index e19cb288..74da41f7 100644
--- a/app/search/page.tsx
+++ b/app/search/page.tsx
@@ -17,7 +17,7 @@ export default function Page({
return (
<AI initialAIState={{ chatId: id, messages: [] }}>
- <Chat id={id} />
+ <Chat id={id} query={searchParams.q} />
</AI>
)
}
diff --git a/components/chat.tsx b/components/chat.tsx
index 21e47d22..04f37544 100644
--- a/components/chat.tsx
+++ b/components/chat.tsx
@@ -8,13 +8,12 @@ import { useUIState, useAIState } from 'ai/rsc'
type ChatProps = {
id?: string
+ query?: string
}
-export function Chat({ id }: ChatProps) {
+export function Chat({ id, query }: ChatProps) {
const router = useRouter()
const path = usePathname()
- const searchParams = useSearchParams()
- const query = searchParams.get('q') || undefined
const [messages] = useUIState()
const [aiState] = useAIState()
@@ -25,7 +24,7 @@ export function Chat({ id }: ChatProps) {
) {
window.history.replaceState({}, '', `/search/${id}`)
}
- }, [id, path, messages, query, searchParams])
+ }, [id, path, messages, query])
useEffect(() => {
if (aiState.messages[aiState.messages.length - 1]?.type === 'followup') {