Skip to content

Commit 4807164

Browse files
remove: use server from router actions (#719)
1 parent f5016dd commit 4807164

File tree

2 files changed

+1
-37
lines changed

2 files changed

+1
-37
lines changed

src/routes/solid-router/concepts/actions.mdx

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -109,42 +109,6 @@ export function MyComponent() {
109109
}
110110
```
111111

112-
## Server actions
113-
114-
Sometimes we need to make sure our action _only_ runs on the server. This is useful for:
115-
116-
- Accessing internal APIs.
117-
- Proxying external APIs.
118-
- To use server secrets.
119-
- To reduce the response payload by postprocessing.
120-
- To bypass CORS.
121-
- Running code incompatible with browsers.
122-
- Or even connecting directly to a database. (Take caution, opinions on if this is a good idea are mixed. You should consider separating your backend and frontend).
123-
124-
To do this, put a `"use server";` directive in your action function:
125-
126-
```tsx twoslash {4}
127-
import { action, redirect } from "@solidjs/router";
128-
129-
const isAdmin = action(async (formData: FormData) => {
130-
"use server";
131-
await new Promise((resolve, reject) => setTimeout(resolve, 1000));
132-
const username = formData.get("username");
133-
if (username === "admin") throw redirect("/admin");
134-
return new Error("Invalid username");
135-
});
136-
137-
export function MyComponent() {
138-
return (
139-
<form action={isAdmin} method="post">
140-
<label for="username">Username:</label>
141-
<input type="text" name="username" />
142-
<input type="submit" value="submit" />
143-
</form>
144-
);
145-
}
146-
```
147-
148112
## Error handling
149113

150114
We strongly recommend with actions to "return" errors rather than throwing them. This can help with typing of submissions you'd use with `useSubmission`. This is important especially for handling progressive enhancement where no JS is present in the client so that we can use the error declaratively to render the updated page on the server.

src/routes/solid-router/concepts/nested-routes.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function PageWrapper(props) {
5959
<Route path="/users" component={PageWrapper}>
6060
<Route path="/" component={Users} />
6161
<Route path="/:id" component={User} />
62-
</Route>;
62+
</Route>
6363
```
6464

6565
While the routes are still configured the same, the route elements will appear inside the parent element where the `props.children` was declared.

0 commit comments

Comments
 (0)