onFinish callback values type
@kapa.ai how can I statically type the values prop on antd onFinish callback prop?
values prop in the onFinish callback for an Ant Design form using Refine, you can define a TypeScript interface for the form values and use it in the onFinish function. Here is an example based on the provided knowledge sources:values parameter in the onFinish function.UserFormValues interface defines the shape of the form values.handleOnFinish function is typed with UserFormValues to ensure that the values parameter conforms to this shape.useForm (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-form/#how-can-i-change-the-form-data-before-submitting-it-to-the-api).UserFormValuesUserFormValueshandleOnFinishimport { Create, useForm } from "@refinedev/antd";
import { Form, Input } from "antd";
import React from "react";
// Define an interface for the form values
interface UserFormValues {
name: string;
surname: string;
}
export const UserCreate: React.FC = () => {
const { formProps, saveButtonProps, onFinish } = useForm();
const handleOnFinish = (values: UserFormValues) => {
onFinish({
fullName: `${values.name} ${values.surname}`,
});
};
return (
<Create saveButtonProps={saveButtonProps}>
<Form {...formProps} onFinish={handleOnFinish} layout="vertical">
<Form.Item label="Name" name="name">
<Input />
</Form.Item>
<Form.Item label="Surname" name="surname">
<Input />
</Form.Item>
</Form>
</Create>
);
};