-
-
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
[Doc] Document useRegisterMutationMiddleware #9031
Conversation
@@ -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> |
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.
you should also update Reference.md
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.
Added
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 | ||
} |
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.
Shouldn't this be written as an async function? 🤔
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 | |
} |
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.
indeed
const middlware = (resource, params, options, next) => { | ||
// Do something before the mutation | ||
|
||
// Call the next middleware | ||
next(resource, params, options); | ||
|
||
// Do something after the mutation | ||
} |
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.
same
}); | ||
|
||
const MyImageInput = (props: Omit<ImageInputProps, 'children'>) => { | ||
const middleware = useCallback(handleImageUpload(props.source), [ |
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.
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] |
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.
you will get a warning about handleImageUpload missing in deps
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.
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] |
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.
I no longer see the warning. To me this is good.
No description provided.