Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jan 7, 2025
1 parent 96f718e commit a584405
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/server-actions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "server-actions-example",
"type": "module",
"exports": {
"./inline": "./dist/inline.js",
"./client": "./dist/client.js"
},
"devDependencies": {
"@types/react": "*"
},
"dependencies": {
"react": "*"
}
}
5 changes: 5 additions & 0 deletions examples/server-actions/src/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'

export async function action1() {
return 'action1'
}
7 changes: 7 additions & 0 deletions examples/server-actions/src/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client'

import { action1 } from './action'

export default function Page() {
return <button onClick={action1}>Action 1</button>
}
11 changes: 11 additions & 0 deletions examples/server-actions/src/inline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-ignore externals
import ClientComponent from 'client-component'

export default function Page() {
async function inlineAction() {
'use server'
return 'inline-action'
}

return <ClientComponent action={inlineAction} />
}
6 changes: 6 additions & 0 deletions examples/server-actions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"target": "ES2022"
}
}

0 comments on commit a584405

Please sign in to comment.