Next/13/Replace Use Search Params
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
andsearchParams
params
overwrite any conflicting values insearchParams
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