Skip to content

Fix onSettled call when provided in hook time options#11139

Merged
djhi merged 2 commits intomasterfrom
fix-on-settled
Jan 27, 2026
Merged

Fix onSettled call when provided in hook time options#11139
djhi merged 2 commits intomasterfrom
fix-on-settled

Conversation

@Madeorsk
Copy link
Contributor

@Madeorsk Madeorsk commented Jan 27, 2026

Problem

Fixes #11137
onSettled isn't called anymore when provided in options of useCreate, useDelete and useDeleteMany.

Solution

This is because we define a custom onSettled function when calling useMutationWithMutationMode. The solution is to call onSettled when provided in the options.

How To Test

Here is an example of component that should call onSettled when clicking on the button:

const Example = () => {
    const [settled, setSettled] = useState<string>();
    const [create] = useCreate(
        'foo',
        { data: { bar: 'baz' } },
        { onSettled: () => setSettled('settled') }
    );

    return (
        <>
            <button onClick={() => create()}>Create</button>
            {settled}
        </>
    );
};

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

@Madeorsk Madeorsk added the RFR Ready For Review label Jan 27, 2026
create: jest.fn(() => Promise.resolve({ data: { id: 1 } } as any)),
});
let localCreate;
let settled = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the test code be simpler if you passed a jest.fn to the onSettled option and checked it was called?

@djhi djhi added this to the 5.14.1 milestone Jan 27, 2026
@djhi djhi merged commit cad5198 into master Jan 27, 2026
15 checks passed
@djhi djhi deleted the fix-on-settled branch January 27, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

onSettled of useCreate is overridden by internal use of onSettled

2 participants