-
Hello I've been using next-safe-action v6 for a while, and need to migrate to v7 to update to nextjs@14.2.8 and typescript@5.5.4. But how can I use Here's my action: "use server";
import { z } from "zod";
import { zfd } from "zod-form-data";
import { action } from "~/lib/next-safe-action";
const schema = zfd.formData({
name: zfd.text(z.string()),
description: zfd.text(z.string()),
currentUrl: zfd.text(z.string()).optional(),
});
export const createIssue = action
.schema(schema)
.stateAction<string | null>(async ({ parsedInput, ctx: { session } }) => {
return "test"
}); And here is how I'm trying to use it: export function BugDialog(props: BugDialogProps) {
const [state, dispatch] = useFormState(createIssue, null);
return (
<form action={dispatch}>
// form stuff
</form>
);
} And this works, I can see the action being called etc. But I keep getting this huge type error in VSCode:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, the TS error should go away if you simply pass an empty object as the second parameter of export function BugDialog(props: BugDialogProps) {
- const [state, dispatch] = useFormState(createIssue, null);
+ const [state, dispatch] = useFormState(createIssue, {});
... |
Beta Was this translation helpful? Give feedback.
Hi, the TS error should go away if you simply pass an empty object as the second parameter of
useFormState
. Safe action result is an object with optional properties; since you need to provide the initial state touseFormState
,{}
is all that's needed for the initial state: