Skip to content

Commit

Permalink
Revert "Revert "docs: update the location of the re-loader to be unde…
Browse files Browse the repository at this point in the history
…r /(qwik-cty) instead of /cookbook (QwikDev#6794)""

This reverts commit 5ab562a.
  • Loading branch information
maiieul committed Aug 27, 2024
1 parent 980664a commit 0c01a6e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/docs/src/routes/docs/(qwikcity)/action/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ created_at: '2023-03-20T23:45:13Z'

# `routeAction$()`

`routeAction$()` is used to define functions called actions that execute exclusively on the server, and only when explicitly called. Actions can have side effects such as writing to a database or sending an email, that cannot happen during client-side rendering. This makes them ideal for handling form submissions, performing operations with side effects, and then returning data back to the client/browser where it can be used to update the UI.
`routeAction$()` is used to define functions called actions that execute exclusively on the server, and only when explicitly called. Actions can have side effects such as writing to a database or sending an email, that cannot happen during client-side rendering. This makes them ideal for handling form submissions, performing operations with side effects, and then returning data back to the client/browser where it can be used to update the UI.

Actions can be declared using `routeAction$()` or `globalAction$()` exported from `@builder.io/qwik-city`.

Expand Down Expand Up @@ -256,15 +256,15 @@ Please refer to the [Zod documentation](https://zod.dev/) for more information o

### Advanced event based validation

The constructor of ```zod$``` can also take a function, as the first argument is zod itself, so you can use this directly to build the schema.
The constructor of ```zod$``` can also take a function, as the first argument is zod itself, so you can use this directly to build the schema.
The second parameter is the RequestEvent to construct an event-based zod schema.
Especially in combination with ```refine``` and ```superRefine``` in zod, the only limit is your imagination.


```tsx {5-5} /ev/#a title="Advanced event based validation"
export const useAddUser = routeAction$(
async (user) => {
// The "user" is still strongly typed, but firstname
// The "user" is still strongly typed, but firstname
// is now optional: { firstName?: string | undefined, lastName: string }
const userID = await db.users.add({
firstName: user.firstName,
Expand Down Expand Up @@ -341,7 +341,7 @@ export const useAddUser = routeAction$(

Failures are stored in the `action.value` property, just like the success value. However, the `action.value.failed` property is set to `true` when the action fails. Futhermore, failure messages can be found in the `fieldErrors` object according to properties defined in your Zod schema.

The `fieldErrors` become a dot notation object. See [Complex forms](/docs/advanced/complex-forms) for more information.
The `fieldErrors` become a dot notation object. See [Complex forms](/docs/advanced/complex-forms) for more information.

```tsx
import { component$ } from '@builder.io/qwik';
Expand Down Expand Up @@ -397,7 +397,7 @@ It's recommended to start with `routeAction$()`. Use `globalAction$()` only when

`routeAction$()` can only be declared inside the `src/routes` folder, in a `layout.tsx` or `index.tsx` file, and they MUST be exported, just like a `routeLoader$()`. Since `routeAction$()`s are only accessible within the route it's declared, they are recommended when the action needs to access some user data, or it's a protected route. Think about it like a "private" action.

> If you want to manage common reusable routeAction$() it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception. For more information [check the cookbook](/docs/cookbook/re-exporting-loaders/index.mdx).
> If you want to manage common reusable routeAction$() it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception. For more information [check this section](/docs/(qwikcity)/re-exporting-loaders/index.mdx).
```tsx title="src/routes/form/index.tsx"
import { routeAction$ } from '@builder.io/qwik-city';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Route Loaders load data in the server so it becomes available to use inside Qwik

Route Loaders can only be declared inside the `src/routes` folder, in a `layout.tsx` or `index.tsx` file, and they MUST be exported.

> If you want to manage common reusable routeLoaders$ it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception. For more information [check the cookbook](/docs/cookbook/re-exporting-loaders/index.mdx).
> If you want to manage common reusable routeLoaders$ it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception. For more information [check this section](/docs/(qwikcity)/re-exporting-loaders/index.mdx).
```tsx /routeLoader$/ /useProductData/#a title="src/routes/product/[productId]/index.tsx"
import { component$ } from '@builder.io/qwik';
Expand Down Expand Up @@ -238,5 +238,3 @@ export default component$(() => {
Route Loaders are executed on the server, after every navigation. This means that they are executed every time a user navigates to a page in an SPA or MPA, and they are executed even if the user is navigating to the same page.

Loaders execute after the Qwik Middleware handlers (`onRequest`, `onGet`, `onPost`, etc), and before the Qwik Components are rendered. This allows the loaders to start fetching data as soon as possible, reducing latency.


2 changes: 1 addition & 1 deletion packages/docs/src/routes/docs/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [Endpoints](</docs/(qwikcity)/endpoints/index.mdx>)
- [Middleware](</docs/(qwikcity)/middleware/index.mdx>)
- [server$](</docs/(qwikcity)/server$/index.mdx>)
- [Re-exporting loaders](/docs/(qwikcity)/re-exporting-loaders/index.mdx)
- [Caching](</docs/(qwikcity)/caching/index.mdx>)
- [HTML attributes](</docs/(qwikcity)/html-attributes/index.mdx>)
- [API reference](</docs/(qwikcity)/api/index.mdx>)
Expand All @@ -46,7 +47,6 @@
- [NavLink](/docs/cookbook/nav-link/index.mdx)
- [Node Docker deploy](/docs/cookbook/node-docker-deploy/index.mdx)
- [Portals](/docs/cookbook/portals/index.mdx)
- [Re-exporting loaders](/docs/cookbook/re-exporting-loaders/index.mdx)
- [Streaming loaders](/docs/cookbook/streaming-deferred-loaders/index.mdx)
- [Sync events w state](/docs/cookbook/sync-events/index.mdx)
- [Theme Managment](/docs/cookbook/theme-management/index.mdx)
Expand Down

0 comments on commit 0c01a6e

Please sign in to comment.