-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support stateful actions via
stateAction
method and `useState…
…Action` hook (#110) This PR adds support for stateful actions (used for React `useActionState` hook) via the `stateAction` method, and the `useStateAction` hook.
- Loading branch information
Showing
78 changed files
with
9,160 additions
and
6,001 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
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
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
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
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
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
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
apps/playground/src/app/(examples)/client-form/signup-action.ts
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
apps/playground/src/app/(examples)/empty-response/empty-action.ts
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 server"; | ||
|
||
import { action } from "@/lib/safe-action"; | ||
import { z } from "zod"; | ||
|
||
const schema = z.object({ | ||
userId: z.string().uuid(), | ||
}); | ||
|
||
export const emptyAction = action | ||
.metadata({ actionName: "emptyAction" }) | ||
.schema(schema) | ||
.action(async () => { | ||
await new Promise((res) => setTimeout(res, 500)); | ||
}); |
44 changes: 44 additions & 0 deletions
44
apps/playground/src/app/(examples)/empty-response/page.tsx
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,44 @@ | ||
"use client"; | ||
|
||
import { StyledButton } from "@/app/_components/styled-button"; | ||
import { StyledHeading } from "@/app/_components/styled-heading"; | ||
import { useAction } from "next-safe-action/hooks"; | ||
import { ResultBox } from "../../_components/result-box"; | ||
import { emptyAction } from "./empty-action"; | ||
|
||
export default function EmptyResponse() { | ||
const { execute, result, status, reset } = useAction(emptyAction, { | ||
onSuccess({ data, input }) { | ||
console.log("HELLO FROM ONSUCCESS", data, input); | ||
}, | ||
onError({ error, input }) { | ||
console.log("OH NO FROM ONERROR", error, input); | ||
}, | ||
onSettled({ result, input }) { | ||
console.log("HELLO FROM ONSETTLED", result, input); | ||
}, | ||
onExecute({ input }) { | ||
console.log("HELLO FROM ONEXECUTE", input); | ||
}, | ||
}); | ||
|
||
console.log("status:", status); | ||
|
||
return ( | ||
<main className="w-96 max-w-full px-4"> | ||
<StyledHeading>Action without response data</StyledHeading> | ||
<StyledButton | ||
type="button" | ||
className="mt-4" | ||
onClick={() => { | ||
execute({ userId: crypto.randomUUID() }); | ||
}}> | ||
Execute action | ||
</StyledButton> | ||
<StyledButton className="mt-4" type="button" onClick={reset}> | ||
Reset | ||
</StyledButton> | ||
<ResultBox result={result} status={status} /> | ||
</main> | ||
); | ||
} |
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
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
Oops, something went wrong.