Skip to content

Commit

Permalink
Merge pull request #10360 from marmelab/fix-use-register-mutation-mid…
Browse files Browse the repository at this point in the history
…dleware-doc

[Doc] Fix `useRegisterMutationMiddleware` documentation
  • Loading branch information
fzaninotto authored Nov 18, 2024
2 parents 75f547f + 2a2f16a commit a17709d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/useRegisterMutationMiddleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ const MyComponent = () => {
// Do something before the mutation

// Call the next middleware
await next(resource, params);
const result = await next(resource, params);

// Do something after the mutation

// Always return the result
return result;
}
const memoizedMiddleWare = React.useCallback(createMiddleware, []);
useRegisterMutationMiddleware(memoizedMiddleWare);
Expand All @@ -67,9 +70,12 @@ const middlware = async (resource, params, next) => {
// Do something before the mutation

// Call the next middleware
await next(resource, params);
const result = await next(resource, params);

// Do something after the mutation

// Always return the result
return result;
}
```

Expand Down Expand Up @@ -100,7 +106,7 @@ const ThumbnailInput = () => {
const b64 = await convertFileToBase64(params.data.thumbnail);
// Update the parameters that will be sent to the dataProvider call
const newParams = { ...params, data: { ...data, thumbnail: b64 } };
await next(resource, newParams);
return next(resource, newParams);
}, []);
useRegisterMutationMiddleware(middleware);

Expand Down

0 comments on commit a17709d

Please sign in to comment.