Skip to content
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

[Doc] Document useRegisterMutationMiddleware #9031

Merged
merged 9 commits into from
Jul 3, 2023
Merged

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Jun 20, 2023

No description provided.

docs/useRegisterMutationMiddleware.md Show resolved Hide resolved
docs/useRegisterMutationMiddleware.md Outdated Show resolved Hide resolved
docs/useRegisterMutationMiddleware.md Outdated Show resolved Hide resolved
docs/useRegisterMutationMiddleware.md Outdated Show resolved Hide resolved
docs/useRegisterMutationMiddleware.md Show resolved Hide resolved
docs/useRegisterMutationMiddleware.md Outdated Show resolved Hide resolved
docs/useRegisterMutationMiddleware.md Outdated Show resolved Hide resolved
docs/useRegisterMutationMiddleware.md Outdated Show resolved Hide resolved
docs/useRegisterMutationMiddleware.md Outdated Show resolved Hide resolved
@@ -119,6 +119,7 @@
<li {% if page.path == 'useEditContext.md' %} class="active" {% endif %}><a class="nav-link" href="./useEditContext.html"><code>useEditContext</code></a></li>
<li {% if page.path == 'useEditController.md' %} class="active" {% endif %}><a class="nav-link" href="./useEditController.html"><code>useEditController</code></a></li>
<li {% if page.path == 'useSaveContext.md' %} class="active" {% endif %}><a class="nav-link" href="./useSaveContext.html"><code>useSaveContext</code></a></li>
<li {% if page.path == 'useRegisterMutationMiddleware.md' %} class="active" {% endif %}><a class="nav-link" href="./useRegisterMutationMiddleware.html"><code>useRegisterMutationMiddleware</code></a></li>
Copy link
Contributor

Choose a reason for hiding this comment

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

you should also update Reference.md

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

Comment on lines 36 to 48
const createMiddleware = (
resource: string,
params: CreateParams,
options: MutateOptions,
next: CreateMutationFunction
) => {
// Do something before the mutation

// Call the next middleware
next(resource, params, options);

// Do something after the mutation
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be written as an async function? 🤔

Suggested change
const createMiddleware = (
resource: string,
params: CreateParams,
options: MutateOptions,
next: CreateMutationFunction
) => {
// Do something before the mutation
// Call the next middleware
next(resource, params, options);
// Do something after the mutation
}
const createMiddleware = async (
resource: string,
params: CreateParams,
options: MutateOptions,
next: CreateMutationFunction
) => {
// Do something before the mutation
// Call the next middleware
await next(resource, params, options);
// Do something after the mutation
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

indeed

Comment on lines 68 to 75
const middlware = (resource, params, options, next) => {
// Do something before the mutation

// Call the next middleware
next(resource, params, options);

// Do something after the mutation
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same

});

const MyImageInput = (props: Omit<ImageInputProps, 'children'>) => {
const middleware = useCallback(handleImageUpload(props.source), [
Copy link
Contributor

Choose a reason for hiding this comment

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

new linter warning on this line 😬

const middleware = useCallback<Middleware<UseCreateResult[0]>>(
(resource, params, options, next) =>
handleImageUpload(props.source)(resource, params, options, next),
[props.source]
Copy link
Member

Choose a reason for hiding this comment

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

you will get a warning about handleImageUpload missing in deps

Copy link
Contributor

Choose a reason for hiding this comment

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

I no longer see the warning. To me this is good.

const middleware = useCallback<Middleware<UseCreateResult[0]>>(
(resource, params, options, next) =>
handleImageUpload(props.source)(resource, params, options, next),
[props.source]
Copy link
Contributor

Choose a reason for hiding this comment

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

I no longer see the warning. To me this is good.

@slax57 slax57 added this to the 4.11.5 milestone Jul 3, 2023
@slax57 slax57 merged commit 4be368a into master Jul 3, 2023
@slax57 slax57 deleted the doc-mutation-middlewares branch July 3, 2023 12:28
@slax57 slax57 modified the milestones: 4.11.5, 4.12.0 Jul 3, 2023
@slax57 slax57 changed the title Document useRegisterMutationMiddleware [Doc] Document useRegisterMutationMiddleware Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants