-
Notifications
You must be signed in to change notification settings - Fork 2
[Community Docs] Update custom hooks guide with around hooks patterns #56
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| # Custom Hooks | ||||||||||||||||||||||||||||||||||||||||||||
| # Custom Hooks (Updated) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Hooks are the primary way to add cross-cutting logic in FeathersJS — think | ||||||||||||||||||||||||||||||||||||||||||||
| validation, authorization, logging, and data transformation. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -8,7 +8,6 @@ validation, authorization, logging, and data transformation. | |||||||||||||||||||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||||||||||||||||||||
| import type { HookContext } from '../declarations'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // A simple before-create hook that stamps a createdAt field | ||||||||||||||||||||||||||||||||||||||||||||
| export const addTimestamp = async (context: HookContext) => { | ||||||||||||||||||||||||||||||||||||||||||||
| context.data = { | ||||||||||||||||||||||||||||||||||||||||||||
| ...context.data, | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -29,19 +28,28 @@ app.service('messages').hooks({ | |||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ## Around hooks (v6+) | ||||||||||||||||||||||||||||||||||||||||||||
| ## Around hooks (v6+ — NEW SECTION) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| ## Around hooks (v6+ — NEW SECTION) | |
| ## Around hooks (v6+) |
Copilot
AI
Mar 31, 2026
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.
The around hook example types next as Function. Elsewhere in the v6 docs the recommended type is NextFunction (for correct typing and to document the intended contract). Update the example signature accordingly and ensure the type is imported in the snippet.
| export const logDuration = async (context: HookContext, next: Function) => { | |
| import type { HookContext, NextFunction } from '../declarations'; | |
| export const logDuration = async (context: HookContext, next: NextFunction) => { |
Copilot
AI
Mar 31, 2026
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.
The "Composing multiple hooks" snippet introduces hooks imported from @feathersjs/hooks, but there’s no surrounding explanation of what this helper is or how composed is then registered on a service. Consider aligning this with the existing docs patterns (composing via arrays passed to app.service(...).hooks(...)) or explicitly explain the dependency/API and show how to apply composed in a hooks registration.
| ```typescript | |
| import { hooks } from '@feathersjs/hooks'; | |
| const composed = hooks([validateData, addTimestamp, logDuration]); | |
| Using the `hooks` helper from `@feathersjs/hooks`, you can compose several hooks | |
| into a single reusable around hook and then register it like any other hook: | |
| ```typescript | |
| import { hooks } from '@feathersjs/hooks'; | |
| // Compose multiple hooks into a single reusable around hook | |
| const composed = hooks([validateData, addTimestamp, logDuration]); | |
| // Register the composed hook on a service | |
| app.service('messages').hooks({ | |
| around: { | |
| all: [composed], | |
| }, | |
| }); |
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.
The document title includes an editorial marker "(Updated)". Please keep the H1 as the stable guide title (e.g., just "Custom Hooks") and avoid versioning/status notes in the heading.