server-act
Advanced tools
Comparing version 0.0.10 to 1.0.0
# server-act | ||
## 1.0.0 | ||
### Major Changes | ||
- b4318a8: Get `formAction` out of experimental! | ||
## 0.0.10 | ||
@@ -4,0 +10,0 @@ |
@@ -38,5 +38,5 @@ import { z } from 'zod'; | ||
/** | ||
* ***Experimental*** - Create an action for React `useFormState` | ||
* Create an action for React `useFormState` | ||
*/ | ||
experimental_formAction: <TState>(action: (params: Prettify<{ | ||
formAction: <TState>(action: (params: Prettify<{ | ||
ctx: InferContextType<TParams['_context']>; | ||
@@ -43,0 +43,0 @@ prevState: any; |
@@ -154,3 +154,3 @@ "use strict"; | ||
}, | ||
experimental_formAction: (action) => { | ||
formAction: (action) => { | ||
return async (prevState, formData) => { | ||
@@ -157,0 +157,0 @@ var _a; |
{ | ||
"name": "server-act", | ||
"version": "0.0.10", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/chungweileong94/server-act#readme", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -83,5 +83,8 @@ # Server-Act | ||
### _(Experimental)_ `useFormState` Support | ||
### `useFormState` Support | ||
> `useFormState` Documentation: https://nextjs.org/docs/app/building-your-application/data-fetching/forms-and-mutations#error-handling | ||
> `useFormState` Documentation: | ||
> | ||
> - https://nextjs.org/docs/app/building-your-application/data-fetching/forms-and-mutations#error-handling | ||
> - https://react.dev/reference/react-dom/hooks/useFormState | ||
@@ -103,3 +106,3 @@ ```ts | ||
) | ||
.experimental_formAction(async ({ input, formErrors, ctx }) => { | ||
.formAction(async ({ input, formErrors, ctx }) => { | ||
if (formErrors) { | ||
@@ -106,0 +109,0 @@ return { formErrors: formErrors.formErrors.fieldErrors }; |
@@ -67,3 +67,3 @@ import {test, expect, expectTypeOf, vi, beforeEach, describe} from 'vitest'; | ||
test('should able to create form action without input', async () => { | ||
const action = serverAct.experimental_formAction(async () => Promise.resolve('bar')); | ||
const action = serverAct.formAction(async () => Promise.resolve('bar')); | ||
@@ -79,5 +79,3 @@ expectTypeOf(action).parameter(0).toBeString(); | ||
test('should able to create form action with input', async () => { | ||
const action = serverAct | ||
.input(z.object({foo: z.string()})) | ||
.experimental_formAction(async () => Promise.resolve('bar')); | ||
const action = serverAct.input(z.object({foo: z.string()})).formAction(async () => Promise.resolve('bar')); | ||
@@ -96,3 +94,3 @@ expectTypeOf(action).parameter(0).toBeString(); | ||
.input(z.object({foo: z.string({required_error: 'Required'})})) | ||
.experimental_formAction(async ({formErrors}) => { | ||
.formAction(async ({formErrors}) => { | ||
if (formErrors) { | ||
@@ -99,0 +97,0 @@ return formErrors; |
@@ -50,5 +50,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/** | ||
* ***Experimental*** - Create an action for React `useFormState` | ||
* Create an action for React `useFormState` | ||
*/ | ||
experimental_formAction: <TState>( | ||
formAction: <TState>( | ||
action: ( | ||
@@ -105,3 +105,3 @@ params: Prettify< | ||
}, | ||
experimental_formAction: (action) => { | ||
formAction: (action) => { | ||
return async (prevState, formData) => { | ||
@@ -108,0 +108,0 @@ const ctx = await _def.middleware?.(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
134
54633
618