Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates on-demand-rendering.mdx #9552

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/content/docs/en/guides/on-demand-rendering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,19 @@ A page or API endpoint rendered on demand can check, set, get, and delete cookie

The example below updates the value of a cookie for a page view counter:

```astro title="src/pages/index.astro" {6,7,11}
```astro title="src/pages/index.astro" {6,7,12}
---
export const prerender = false; // Not needed in 'server' mode

let counter = 0

if (Astro.cookies.has("counter")) {
const cookie = Astro.cookies.get("counter")
counter = cookie.number() + 1
if (Astro.cookies.has('counter')) {
const cookie = Astro.cookies.get('counter')
const value = cookie?.number()
if (value !== undefined && !isNaN(value)) counter = value + 1
}

Astro.cookies.set("counter",counter)
Astro.cookies.set('counter', String(counter))
---
<html>
<h1>Counter = {counter}</h1>
Expand Down
Loading