Skip to content

Commit e889987

Browse files
Update 'use server' directive explanation
Clarify the usage of 'use server' directive in SolidStart. Proposed as it's often misused, as you can see in the wild: https://github.com/orgs/supabase/discussions/12891
1 parent c9801a1 commit e889987

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/routes/solid-start/reference/server/use-server.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ description: >-
1717
Handle database operations, API calls, and secure logic on the server.
1818
---
1919

20-
`"use server"` will enable functions that only run on the server.
20+
`"use server"` enables functions or files to be executed only on the server. Server functions allow client components to call code that is executed in the server context.
2121

2222
```tsx
23+
// Function-level
2324
const logHello = async (message: string) => {
2425
"use server";
2526
console.log(message);
2627
};
2728
```
29+
Or when using at the top of a file.
30+
```tsx
31+
// File-level
32+
"use server";
33+
34+
const logHello = async (message: string) => {
35+
console.log(message);
36+
};
37+
```
2838

2939
**Note:** `"use server"` functions must be marked async or return a promise.
3040

0 commit comments

Comments
 (0)