github refinedev/refine @refinedev/core@4.40.0

Minor Changes

  • #4914 91a4d0da9f1 Thanks @yildirayunlu! - feat: add optimisticUpdateMap prop to the useUpdate and useUpdateMany hooks

    list, many and detail are the keys of the optimisticUpdateMap object. To automatically update the cache, you should pass true. If you don't want to update the cache, you should pass false.

    If you wish to customize the cache update, you have the option to provide functions for the list, many, and detail keys. These functions will be invoked with the previous data, values, and id parameters. Your responsibility is to return the updated data within these functions.

    const { mutate } = useUpdateMany();
    
    mutate({
        //...
        mutationMode: "optimistic",
        optimisticUpdateMap: {
            list: true,
            many: true,
            detail: (previous, values, id) => {
                if (!previous) {
                    return null;
                }
    
                const data = {
                    id,
                    ...previous.data,
                    ...values,
                    foo: "bar",
                };
    
                return {
                    ...previous,
                    data,
                };
            },
        },
    });
    

    feat: add optimisticUpdateMap prop to the useForm hook

    const { formProps, saveButtonProps } = useForm({
        mutationMode: "optimistic",
        optimisticUpdateMap: {
            list: true,
            many: true,
            detail: (previous, values, id) => {
                if (!previous) {
                    return null;
                }
    
                const data = {
                    id,
                    ...previous.data,
                    ...values,
                    foo: "bar",
                };
    
                return {
                    ...previous,
                    data,
                };
            },
        },
    });
    

Patch Changes

Don't miss a new refine release

NewReleases is sending notifications on new releases.