{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "adapter-inertia",
  "title": "Inertia.js Adapter",
  "author": "François Best <franky47>",
  "description": "Using nuqs in Inertia.js apps (eg: with a Laravel backend)",
  "dependencies": [
    "nuqs"
  ],
  "files": [
    {
      "path": "src/registry/remote/adapter-inertia.aA8JLn5yKHSG.txt",
      "content": "import { router, usePage } from '@inertiajs/react';\nimport {\n  unstable_createAdapterProvider as createAdapterProvider,\n  renderQueryString,\n  type unstable_AdapterInterface as AdapterInterface,\n  type unstable_AdapterOptions as AdapterOptions,\n  type unstable_UpdateUrlFunction as UpdateUrlFunction\n} from 'nuqs/adapters/custom';\nimport * as React from 'react';\n\nfunction useNuqsInertiaAdapter(): AdapterInterface {\n  const currentUrl = usePage().url;\n  // We need the searchParams to be optimistic to avoid\n  // flickering when the internal state is updated\n  // but the URL is not yet updated.\n  const [searchParams, setSearchParams] = React.useState(\n    new URL(currentUrl, location.origin).searchParams\n  );\n\n  React.useEffect(() => {\n    setSearchParams(new URL(currentUrl, location.origin).searchParams);\n  }, [currentUrl]);\n\n  const updateUrl: UpdateUrlFunction = React.useCallback(\n    (search: URLSearchParams, options: AdapterOptions) => {\n      const url = new URL(window.location.href);\n      url.search = renderQueryString(search);\n      setSearchParams(url.searchParams);\n\n      // Server-side request\n      if (options?.shallow === false) {\n        router.visit(url, {\n          replace: options.history === 'replace',\n          preserveScroll: !options.scroll,\n          preserveState: true,\n          async: true\n        });\n        return;\n      }\n\n      const method = options.history === 'replace' ? 'replace' : 'push';\n\n      router[method]({\n        url: url.pathname + url.search + url.hash,\n        clearHistory: false,\n        encryptHistory: false,\n        preserveScroll: !options.scroll,\n        preserveState: true\n      });\n    },\n    []\n  );\n\n  return {\n    searchParams,\n    updateUrl\n  };\n}\n\nexport const NuqsAdapter = createAdapterProvider(useNuqsInertiaAdapter);\n",
      "type": "registry:file",
      "target": "~/resources/js/lib/nuqs-inertia-adapter.ts"
    }
  ],
  "docs": "https://nuqs.dev/registry/adapter-inertia",
  "categories": [
    "adapter"
  ],
  "type": "registry:item"
}