Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

freemium's avatar

Inertia React route paramter error

i am using Inertia +react for learing i am trying to do some update operation but am getting error in form submit function please help me get solved my Update file PradeshEdit.tsx is

interface Props {
    pradesh: {
       id: number;
       name: string;
    }
}

export default function PradeshEdit({pradesh}:Props) {
  
  const route = useRoute();
  const { data, setData, put, processing, errors } = useForm({
    name: pradesh.name,
  });

  function onSubmit(e: React.FormEvent) {
    e.preventDefault();
    put(route('pradeshes.update',pradesh.id), {
      preserveScroll: true,
      onSuccess: () =>
        Swal.fire('Success!', 'Pradesh has been created', 'success'),
    });
  }

my controller is

public function edit(Pradesh $pradesh)
   {
       return Inertia::render('Pradesh/PradeshEdit', [
           'pradesh' => $pradesh
       ])
   }

error shown in vs code terminal is

[{
	"resource": "/c:/xampp/htdocs/rgbproject/govtelemedicine-web/resources/js/Pages/Pradesh/PradeshEdit.tsx",
	"owner": "typescript",
	"code": "2769",
	"severity": 8,
	"message": "No overload matches this call.\n  Overload 1 of 2, '(name?: undefined, params?: RouteParamsWithQueryOverload | undefined, absolute?: boolean | undefined, config?: Config | undefined): Router', gave the following error.\n    Argument of type '\"pradeshes.update\"' is not assignable to parameter of type 'undefined'.\n  Overload 2 of 2, '(name: string, params?: RouteParamsWithQueryOverload | undefined, absolute?: boolean | undefined, config?: Config | undefined): string', gave the following error.\n    Argument of type 'number' is not assignable to parameter of type 'RouteParamsWithQueryOverload | undefined'.",
	"source": "ts",
	"startLineNumber": 37,
	"startColumn": 9,
	"endLineNumber": 37,
	"endColumn": 45
}]```
  function onSubmit(e: React.FormEvent) {
    e.preventDefault();
    put(route('pradeshes.update',pradesh.id), {
      preserveScroll: true,
      onSuccess: () =>
        Swal.fire('Success!', 'Pradesh has been created', 'success'),
    });
  }
0 likes
0 replies

Please or to participate in this conversation.