File tree 4 files changed +12
-6
lines changed
packages/example-app/src/app
(examples)/optimistic-hook
4 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { z } from "zod";
6
6
7
7
let likes = 42 ;
8
8
9
- export const getLikes = ( ) => likes ;
9
+ export const getLikes = async ( ) => likes ;
10
10
11
11
const incrementLikes = ( by : number ) => {
12
12
likes += by ;
Original file line number Diff line number Diff line change @@ -74,7 +74,11 @@ const AddLikesForm = ({ likesCount }: Props) => {
74
74
Reset
75
75
</ StyledButton >
76
76
</ form >
77
- < ResultBox result = { optimisticData } status = { status } />
77
+ < ResultBox
78
+ result = { optimisticData }
79
+ status = { status }
80
+ customTitle = "Optimistic data:"
81
+ />
78
82
</ >
79
83
) ;
80
84
} ;
Original file line number Diff line number Diff line change @@ -2,8 +2,9 @@ import { StyledHeading } from "@/app/_components/styled-heading";
2
2
import { getLikes } from "./addlikes-action" ;
3
3
import AddLikeForm from "./addlikes-form" ;
4
4
5
- export default function OptimisticHook ( ) {
6
- const likesCount = getLikes ( ) ;
5
+ export default async function OptimisticHookPage ( ) {
6
+ const likesCount = await getLikes ( ) ;
7
+
7
8
return (
8
9
< main className = "w-96 max-w-full px-4" >
9
10
< StyledHeading > Action using optimistic hook</ StyledHeading >
Original file line number Diff line number Diff line change @@ -3,15 +3,16 @@ import { HookActionStatus } from "next-safe-action/hooks";
3
3
type Props = {
4
4
result : any ;
5
5
status ?: HookActionStatus ;
6
+ customTitle ?: string ;
6
7
} ;
7
8
8
- export function ResultBox ( { result, status } : Props ) {
9
+ export function ResultBox ( { result, status, customTitle } : Props ) {
9
10
return (
10
11
< div className = "mt-8" >
11
12
{ status ? (
12
13
< p className = "text-lg font-semibold" > Execution status: { status } </ p >
13
14
) : null }
14
- < p className = "text-lg font-semibold" > Action result:</ p >
15
+ < p className = "text-lg font-semibold" > { customTitle || " Action result:" } </ p >
15
16
< pre className = "mt-4" > { JSON . stringify ( result , null , 1 ) } </ pre >
16
17
</ div >
17
18
) ;
You can’t perform that action at this time.
0 commit comments