[Community Docs] Update custom hooks guide with around hooks patterns - #56
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the v6 “Custom Hooks” guide to introduce around hooks usage and add a short example for composing multiple hooks.
Changes:
- Updates the guide title and refreshes the intro/example content.
- Adds an “Around hooks (v6+)” section with a duration-logging around hook example.
- Adds a “Composing multiple hooks” section with a composition snippet.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,4 +1,4 @@ | |||
| # Custom Hooks | |||
| # Custom Hooks (Updated) | |||
There was a problem hiding this comment.
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.
| # Custom Hooks (Updated) | |
| # Custom Hooks |
| ``` | ||
|
|
||
| ## Around hooks (v6+) | ||
| ## Around hooks (v6+ — NEW SECTION) |
There was a problem hiding this comment.
The section header includes "— NEW SECTION", which reads like an internal note. Please remove this so the published heading is just the topic (e.g., "Around hooks (v6+)").
| ## Around hooks (v6+ — NEW SECTION) | |
| ## Around hooks (v6+) |
| call, giving you control of both the before and after phases: | ||
|
|
||
| ```typescript | ||
| export const logDuration = async (context: HookContext, next: Function) => { |
There was a problem hiding this comment.
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) => { |
|
|
||
| ```typescript | ||
| import { hooks } from '@feathersjs/hooks'; | ||
|
|
||
| const composed = hooks([validateData, addTimestamp, logDuration]); |
There was a problem hiding this comment.
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], | |
| }, | |
| }); |
Community Documentation Contribution
Submitted via: FeathersJS MCP Server (
submit_documentationtool)Contributor: Test User
Target version: v6
Category: hooks
File:
docs/v6_docs/guides/custom-hooks.mdType: Update to existing doc
Validation Results
Description
Added around hooks section and updated examples for v6
This PR was automatically generated by the FeathersJS MCP Server contributor pipeline.
Please review the content carefully before merging.