worthy-azureW
Refine3y ago
4 replies
worthy-azure

How to transform a value before it gets sent for a resource update

Hi all!

As the title states, I would like to know what the best practice is for transforming a value before it gets sent to the server to update a resource.

Code:

export const ArtistEdit: React.FC<IResourceComponentsProps> = () =>  {
  const { formProps, saveButtonProps, queryResult } = useForm();
  const artistsData = queryResult?.data?.data;

  return (
    <Edit saveButtonProps={saveButtonProps}>
      <Form.Item
          label="Date Of Birth"
          name={["date_of_birth"]}
          rules={[
            {
              required: true,
            },
          ]}
          getValueProps={(value) => ({
            value: value ? dayjs(value) : undefined,
          })}
        >
          <DatePicker />
        </Form.Item>
    </Edit>

  )

}


In this code sample, I need to make sure the value of date_of_birth conforms to the backends requirement for date parsing.

What is best practice here to do when working solely with refine?
Was this page helpful?