react-form-action 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -382,6 +382,8 @@ export function SignUpForm() {
|
|
|
382
382
|
|
|
383
383
|
Render children when the action is pending:
|
|
384
384
|
|
|
385
|
+
#### When children are JSX
|
|
386
|
+
|
|
385
387
|
```tsx
|
|
386
388
|
import { Action, Pending } from "react-form-action/client";
|
|
387
389
|
|
|
@@ -392,9 +394,29 @@ return function MyForm() {
|
|
|
392
394
|
<Action action={action}>
|
|
393
395
|
{/* 👉 Unlike the React.useFormStatus() hook, we don't need here the <form> element at all. */}
|
|
394
396
|
<Pending>
|
|
397
|
+
{/* 👉 The spinner will UNMOUNT when the action is NOT pending */}
|
|
395
398
|
<Spinner />
|
|
396
399
|
</Pending>
|
|
397
400
|
</Action>
|
|
398
401
|
);
|
|
399
402
|
};
|
|
400
403
|
```
|
|
404
|
+
|
|
405
|
+
#### When children is a render prop
|
|
406
|
+
|
|
407
|
+
```tsx
|
|
408
|
+
import { Pending } from "react-form-action/client";
|
|
409
|
+
|
|
410
|
+
return function SubmitButton() {
|
|
411
|
+
return (
|
|
412
|
+
<Pending>
|
|
413
|
+
{({ isPending }) => (
|
|
414
|
+
{/* 👉 With a render prop, the children are always mounted, regardles of the isPending flag */}
|
|
415
|
+
<button type="submit" disabled={isPending}>
|
|
416
|
+
{isPending ? "Submitting..." : "Submit"}
|
|
417
|
+
</button>
|
|
418
|
+
)}
|
|
419
|
+
</Pending>
|
|
420
|
+
);
|
|
421
|
+
};
|
|
422
|
+
```
|
package/dist/client.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { PropsWithChildren, JSX } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { F as FormAction, A as ActionState, I as InitialState, a as InvalidState, b as FailureState, S as SuccessState } from './createFormAction-CX4Fk5xA.mjs';
|
|
4
4
|
import { ZodFormattedError } from 'zod';
|
|
5
|
-
import { RenderProp } from 'react-render-prop-type';
|
|
5
|
+
import { RenderProp, RP } from 'react-render-prop-type';
|
|
6
6
|
import { useFormStatus } from 'react-dom';
|
|
7
7
|
|
|
8
8
|
type ActionProps<Data, Error, ValidationError> = PropsWithChildren<{
|
|
@@ -61,8 +61,8 @@ declare function ZodFieldError<Errors extends ZodFormattedError<any>>({ errors,
|
|
|
61
61
|
* Creates a typed components for actions created with the formAction builder.
|
|
62
62
|
*/
|
|
63
63
|
declare function createComponents<Data, Error, ValidationError extends ZodFormattedError<any>>(action: FormAction<Data, Error, ValidationError>): {
|
|
64
|
-
FieldError: ({ name, }:
|
|
65
|
-
name?: "" | InferZodErrorPaths<ValidationError
|
|
64
|
+
FieldError: ({ name, }: PropsWithChildren<{
|
|
65
|
+
name?: "" | InferZodErrorPaths<ValidationError>;
|
|
66
66
|
}>) => false | React__default.JSX.Element;
|
|
67
67
|
};
|
|
68
68
|
|
|
@@ -71,6 +71,8 @@ declare function FormStatus({ children, }: RenderProp<ReturnType<typeof useFormS
|
|
|
71
71
|
/**
|
|
72
72
|
* Conditionally renders the children, when the form action is in the "pending" state.
|
|
73
73
|
*/
|
|
74
|
-
declare function Pending({ children }: PropsWithChildren
|
|
74
|
+
declare function Pending({ children, }: PropsWithChildren | RP<{
|
|
75
|
+
isPending: boolean;
|
|
76
|
+
}>): React.ReactNode;
|
|
75
77
|
|
|
76
|
-
export { Action, ActionContextState, ActionProps, Form, FormProps, FormStatus, InferZodErrorPaths, Paths, Pending, ZodFieldError, ZodFieldErrorProps, createComponents, useActionContext };
|
|
78
|
+
export { Action, type ActionContextState, type ActionProps, Form, type FormProps, FormStatus, type InferZodErrorPaths, type Paths, Pending, ZodFieldError, type ZodFieldErrorProps, createComponents, useActionContext };
|
package/dist/client.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{a as c}from"./chunk-HL47DG4L.mjs";import f from"react";import{createContext as E,use as x}from"react";import{useActionState as
|
|
1
|
+
"use client";import{a as c}from"./chunk-HL47DG4L.mjs";import f from"react";import{createContext as E,use as x}from"react";import{useActionState as y}from"react";var p={isInitial:!1,isInvalid:!1,isFailure:!1,isSuccess:!1},m=E(null);function a(t){let o=x(m);if(!o)throw new Error("ActionContext must be initialized before use. Is your useActionContext hook wrapped with an <Action> Component?");return o}function g({children:t,action:o,initialData:e,permalink:n}){let[r,i,s]=y(o,c(e),n),d=r.type==="initial"?{...r,...p,action:i,isPending:s,isInitial:!0}:r.type==="invalid"?{...r,...p,action:i,isPending:s,isInvalid:!0}:r.type==="failure"?{...r,...p,action:i,isPending:s,isFailure:!0}:{...r,...p,action:i,isPending:s,isSuccess:!0};return f.createElement(m,{value:d},t)}import S,{startTransition as A}from"react";function V({autoReset:t=!1,...o}){let{action:e}=a();return S.createElement("form",{...t?{action:e}:{onSubmit:r=>{r.preventDefault();let i=r.currentTarget;A(()=>{e(new FormData(i))})}},...o})}import C from"react";import u from"react";var F=".",P=Object.freeze({_errors:Object.freeze([])});function l({errors:t,name:o="",children:e=({errors:n})=>u.createElement(u.Fragment,null,n[0])}){if(o.length===0)return e({errors:t._errors});let n=o.split(F),r=t;for(;n.length;){let i=n.shift();r=r[i]??P}return e({errors:r._errors})}function $(t){function o({name:e}){let{isInvalid:n,validationError:r}=a(t);return n&&C.createElement(l,{errors:r,name:e})}return{FieldError:o}}import{useFormStatus as h}from"react-dom";function X({children:t}){return t(h())}function q({children:t}){let{isPending:o}=a();return typeof t=="function"?t({isPending:o}):o&&t}export{g as Action,V as Form,X as FormStatus,q as Pending,l as ZodFieldError,$ as createComponents,a as useActionContext};
|
|
@@ -31,4 +31,4 @@ declare function createFormAction<Data, Error = Data, ValidationError = Record<s
|
|
|
31
31
|
invalid: (validationError: ValidationError) => InvalidState<ValidationError>;
|
|
32
32
|
}) => FormAction<Data, Error, ValidationError, Payload>): (state: ActionState<Data, Error, ValidationError>, payload: Payload) => Promise<ActionState<Data, Error, ValidationError>>;
|
|
33
33
|
|
|
34
|
-
export { ActionState as A,
|
|
34
|
+
export { type ActionState as A, type FormAction as F, type InitialState as I, type SuccessState as S, type InvalidState as a, type FailureState as b, createFormAction as c, initial as i };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as ActionState,
|
|
2
|
-
export {
|
|
1
|
+
import { A as ActionState, a as InvalidState, b as FailureState, S as SuccessState } from './createFormAction-CX4Fk5xA.mjs';
|
|
2
|
+
export { F as FormAction, I as InitialState, c as createFormAction, i as initial } from './createFormAction-CX4Fk5xA.mjs';
|
|
3
3
|
import { ZodTypeAny, ZodType, ZodObject, ZodRawShape, objectUtil, z, ZodSchema, ZodEffects } from 'zod';
|
|
4
4
|
|
|
5
5
|
declare const emptyInput: unique symbol;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-form-action",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "State management helpers for the react form actions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
".": {
|
|
24
24
|
"import": "./dist/index.mjs",
|
|
25
25
|
"module": "./dist/index.mjs",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
28
|
},
|
|
29
29
|
"./client": {
|
|
30
30
|
"import": "./dist/client.mjs",
|
|
31
31
|
"module": "./dist/client.mjs",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"types": "./dist/client.d.mts",
|
|
33
|
+
"default": "./dist/client.mjs"
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"@types/react": "^19.0.0",
|
|
59
59
|
"@types/react-dom": "^19.0.1",
|
|
60
60
|
"@vitejs/plugin-react": "^4.3.4",
|
|
61
|
-
"happy-dom": "^
|
|
62
|
-
"npm-check-updates": "^17.1.
|
|
61
|
+
"happy-dom": "^16.0.0",
|
|
62
|
+
"npm-check-updates": "^17.1.12",
|
|
63
63
|
"prettier": "^3.4.2",
|
|
64
64
|
"react": "^19.0.0",
|
|
65
65
|
"react-dom": "^19.0.0",
|
|
66
|
-
"react-render-prop-type": "^
|
|
67
|
-
"tsup": "^
|
|
68
|
-
"typescript": "^5.
|
|
66
|
+
"react-render-prop-type": "^1.0.0",
|
|
67
|
+
"tsup": "^8.3.5",
|
|
68
|
+
"typescript": "^5.7.2",
|
|
69
69
|
"vitest": "^1.3.1",
|
|
70
70
|
"zod": "^3.23.8",
|
|
71
71
|
"zod-form-data": "^2.0.2"
|