Next.js Discord

Discord Forum

Wrapping code in suspense?

Answered
Clumber Spaniel posted this in #help-forum
Open in Discord
Avatar
Clumber SpanielOP
How do i wrap this in suspense?
Image
Answered by chisto
you can make it a component, i usually do this
and inside the component i put all the logic and stuff that was on the Page

export default function Page() {
return (
<Suspense>
<Component />
</Suspense>
);
}
View full answer

10 Replies

Avatar
you have to wrap the whole component in the parent component

<Suspense>
<ThisComponent />
</Suspense>
btw, why do you wrap that code in suspense?
Avatar
because they used useSearchParams() in SSG
so Suspense is forced
Avatar
Clumber SpanielOP
Its not a component though, ots in page.tsx
How do i wrap it then?
Avatar
you can make it a component, i usually do this
and inside the component i put all the logic and stuff that was on the Page

export default function Page() {
return (
<Suspense>
<Component />
</Suspense>
);
}
Answer
Avatar
Clumber SpanielOP
I see, fixed it, thanks
Avatar
can you mark as solved the answer that helped u most?