Skip to content

Commit

Permalink
update vercel example
Browse files Browse the repository at this point in the history
  • Loading branch information
nitedani committed Aug 6, 2024
1 parent 8c5cfde commit ff48276
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
3 changes: 3 additions & 0 deletions examples/express-react-vercel/pages/+Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function Layout({ children }) {
<a className="navitem" href="/dynamic">
Dynamic
</a>
<a className="navitem" href="/static">
Static
</a>
</Sidebar>
<Content>{children}</Content>
</PageLayout>
Expand Down
21 changes: 18 additions & 3 deletions examples/express-react-vercel/pages/dynamic/+Page.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
export default Page

import React from 'react'
import React, { useState } from 'react'

function Page() {
return (
<>
<h1>Dynamic</h1>
This page is rendered to HTML at {new Date().toLocaleString('en')}.
<h1>Welcome</h1>
This page is:
<ul>
<li>Dynamic</li>
<li>No static html generated</li>
<li>Interactive</li>
</ul>
<Counter />
</>
)
}

function Counter() {
const [count, setCount] = useState(0)
return (
<button type="button" onClick={() => setCount((count) => count + 1)}>
Counter {count}
</button>
)
}
21 changes: 18 additions & 3 deletions examples/express-react-vercel/pages/index/+Page.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
export default Page

import React from 'react'
import React, { useState } from 'react'

function Page() {
return (
<>
<h1>Pre-rendered</h1>
This page is pre-rendered to HTML at {new Date().toLocaleString('en')}.
<h1>Welcome</h1>
This page is:
<ul>
<li>Pre-rendered</li>
<li>Static html generated</li>
<li>Interactive</li>
</ul>
<Counter />
</>
)
}

function Counter() {
const [count, setCount] = useState(0)
return (
<button type="button" onClick={() => setCount((count) => count + 1)}>
Counter {count}
</button>
)
}
27 changes: 27 additions & 0 deletions examples/express-react-vercel/pages/static/+Page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default Page

import React, { useState } from 'react'

function Page() {
return (
<>
<h1>Welcome</h1>
This page is:
<ul>
<li>Pre-rendered</li>
<li>Static html generated</li>
<li>Not interactive (no javascript is downloaded for this page)</li>
</ul>
<Counter />
</>
)
}

function Counter() {
const [count, setCount] = useState(0)
return (
<button type="button" onClick={() => setCount((count) => count + 1)}>
Counter {count}
</button>
)
}
10 changes: 10 additions & 0 deletions examples/express-react-vercel/pages/static/+config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://vike.dev/render-modes#html-only

export default {
prerender: true,
meta: {
Page: {
env: { server: true, client: false }
}
}
}

0 comments on commit ff48276

Please sign in to comment.