#Why is this error occuring
1 messages · Page 1 of 1 (latest)
The error message you're seeing is related to the use of the useSearchParams() hook in your Next.js application. This hook is part of the new React 18 features and is used to access the query parameters of the current URL. However, it requires being wrapped in a React Suspense component to handle loading states while the search parameters are being retrieved.
The error is occurring because the useSearchParams() hook is being used in a component that is not wrapped in a Suspense component. This is required because useSearchParams() is a suspenseful operation, meaning it might not finish immediately and React needs to know how to handle this delay.
To fix this issue, you should wrap the component that uses useSearchParams() in a Suspense component. Here's an example of how to do this:
import { Suspense } from 'react';
import { useSearchParams } from 'react-router-dom';
function MyComponent() {
return (
<Suspense fallback={<div>Loading...</div>}>
<ComponentUsingSearchParams />
</Suspense>
);
}
function ComponentUsingSearchParams() {
const [searchParams] = useSearchParams();
// rest of your component
}
In this example, ComponentUsingSearchParams is the component that uses the useSearchParams() hook. It's wrapped in a Suspense component in MyComponent, which provides a fallback UI (<div>Loading...</div>) for React to show while it's waiting for useSearchParams() to finish.
If you're not exporting a component but just using it for a value, you should create a secondary component that uses it, or provide a loading.tsx file alongside your page.jsx, which will automatically wrap the exported page with suspense and use the contents of the loading file as the fallback. Source (https://github.com/vercel/next.js/issues/67398)
If you're still facing issues, some users have reported that setting missingSuspenseWithCSRBailout: false in the experimental section of your Next.js config can help. Source (https://github.com/vercel/next.js/issues/61697)
const nextConfig = {
experimental: {
missingSuspenseWithCSRBailout: false,
},
};