May 8, 2022
0
Level 1
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'),
});
}
Please or to participate in this conversation.