-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move middlewares to dataProvider hooks #9855
Conversation
You should update the docs, too (cf https://marmelab.com/react-admin/useRegisterMutationMiddleware.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document that change in the upgrade guide, too
b3c6f06
to
f0f095c
Compare
packages/ra-core/src/dataProvider/useUpdate.optimistic.stories.tsx
Outdated
Show resolved
Hide resolved
packages/ra-core/src/dataProvider/useUpdate.undoable.stories.tsx
Outdated
Show resolved
Hide resolved
packages/ra-core/src/dataProvider/useUpdate.optimistic.stories.tsx
Outdated
Show resolved
Hide resolved
packages/ra-core/src/dataProvider/useUpdate.optimistic.stories.tsx
Outdated
Show resolved
Hide resolved
packages/ra-core/src/dataProvider/useUpdate.undoable.stories.tsx
Outdated
Show resolved
Hide resolved
packages/ra-core/src/dataProvider/useUpdate.undoable.stories.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than that LGTM, well done!
Problem
With
react-query
v5, we cannot rely on the side effects callbacks anymore to execute middlewares. Indeed, we had to move the default side effects of the main mutation (update
for instance) at the hook call so that they are called even when the component that triggered the mutation has been unmounted (optimistic
andundoable
with redirections for instance). Because of that, middlewares don't have access to the default side effects anymore.Solution
Apply the middlewares in the function we pass to react-query mutation (for instance, on
dataProvider.update
).We loose the ability to alter side effects. However, the whole mutation (base one with its middlewares applied) can now be cancelled with
undoable
.