Replies: 3 comments 4 replies
|
Does your APP have |
|
This usually happens because of one of a few common reasons:
So the first things I'd check are:
If you share the component where you're calling |
|
This is expected behavior in the Next.js App Router, not a bug. useSearchParams() returns null during static prerendering (at build time). When Next.js statically generates the page, there is no request URL yet, so the hook has no search params to read and returns null on the server. To fix it, wrap the component that calls useSearchParams in a boundary: import { Suspense } from "react";
import { useSearchParams } from "next/navigation";
function SearchResults() {
const params = useSearchParams();
const q = params?.get("q") ?? "";
return <div>Searching for: {q}</div>;
}
export default function Page() {
return (
<Suspense fallback={<div>Loading...</div>}>
<SearchResults />
</Suspense>
);
} |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
My url has query params when It landing. For instance, https://my.com?tab=INFO
But in the init render, useSearchParams returns null value in searchParams.get('tab').
Why this hook doesn't reflect query string on the first render?
How can I get real query string on the first render phase?
Additional information
No response
Example
No response
All reactions