Next.js
migration
byCodemod

Next/13/Replace Use Search Params

/icons/calendar.svg

Last update

Jul 24, 2024

A recent update in Next.js brought a breaking change: the useSearchParams hook no longer includes params. To ease the migration, the new useCompatSearchParams hook can be used. This hook mimics the behavior of the old useSearchParams in two ways:

  • it includes both params and searchParams
  • params overwrite any conflicting values in searchParams

Example

Before

import { useSearchParams } from 'next/navigation';
export async function Component() {
const params = useSearchParams();
return <div>My Component</div>;
}

After

import { useCompatSearchParams } from 'hooks/utils';
export async function Component() {
const params = useCompatSearchParams();
return <div>My Component</div>;
}

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now