-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failing test for
"use cache"
with useActionState
- Loading branch information
1 parent
0c22b00
commit aab8c17
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use cache' | ||
|
||
export async function getRandomValue() { | ||
const v = Math.random() | ||
console.log(v) | ||
return v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use client' | ||
|
||
import { useActionState } from 'react' | ||
import { getRandomValue } from './cached' | ||
|
||
export default function Page() { | ||
const [result, formAction, isPending] = useActionState(getRandomValue, -1) | ||
|
||
return ( | ||
<form action={formAction}> | ||
<button id="submit-button">Submit</button> | ||
<p>{isPending ? 'loading...' : result}</p> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters