Skip to content

Commit 802f8c8

Browse files
committed
correct docs for passing parameters to hooks
1 parent e4e81dd commit 802f8c8

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

packages/docs/src/pages/docs/middleware.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use(userTable, async (ctx) => {
1919
console.log(ctx.params);
2020

2121
// Call the native implementation
22-
const result = await ctx.next();
22+
const result = await ctx.next(...ctx.params);
2323
return result;
2424
})
2525
```

packages/docs/src/pages/docs/reference/use.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Typical usage of `use()` looks like this:
1212
```ts
1313
use(userTable, async (ctx) => {
1414
// Call the next registered hook (or the implementation)
15-
const result = await ctx.next();
15+
const result = await ctx.next(...ctx.params);
1616
// Return results
1717
return result;
1818
});
@@ -56,15 +56,15 @@ Additionally, hooks themselves are called in the reverse order of when they were
5656
// Register a hook on the entire database
5757
use(db, async (ctx) => {
5858
console.log("1");
59-
const result = await ctx.next();
59+
const result = await ctx.next(...ctx.params);
6060
console.log("6");
6161
return result;
6262
});
6363

6464
// Register a hook on the userTable
6565
use(userTable, async (ctx) => {
6666
console.log("2");
67-
const result = await ctx.next();
67+
const result = await ctx.next(...ctx.params);
6868
console.log("5");
6969
return result;
7070
});
@@ -73,7 +73,7 @@ use(userTable, async (ctx) => {
7373
// - this will be called after the second hook
7474
use(userTable, async (ctx) => {
7575
console.log("3");
76-
const result = await ctx.next();
76+
const result = await ctx.next(...ctx.params);
7777
console.log("4");
7878
return result;
7979
});
@@ -116,7 +116,7 @@ The name of the method currently executing a hook can be retrieved with `ctx.act
116116
```ts
117117
use(userTable, async (ctx) => {
118118
console.log(ctx.action);
119-
const result = await ctx.next();
119+
const result = await ctx.next(...ctx.params);
120120
return result;
121121
});
122122

@@ -133,7 +133,7 @@ use(userTable, async (ctx) => {
133133
if(isAction(ctx, "count")) {
134134
console.log("User has executed count()!");
135135
}
136-
const result = await ctx.next();
136+
const result = await ctx.next(...ctx.params);
137137
return result;
138138
});
139139
```
@@ -144,10 +144,10 @@ It provides the same functionality as a `ctx.action === "count"` check, but addi
144144
use(userTable, async (ctx) => {
145145
if(isAction(ctx, "count")) {
146146
// `result` is now typed as `number`!
147-
const result = await ctx.next();
147+
const result = await ctx.next(...ctx.params);
148148
}
149149
// Out here, `result` can be anything - a number, one entity, a list of entities...
150-
const result = await ctx.next();
150+
const result = await ctx.next(...ctx.params);
151151
return result;
152152
});
153153
```

0 commit comments

Comments
 (0)