react-form-action 2.0.0 → 2.0.1
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 +3 -5
- package/dist/client.d.mts +4 -4
- package/dist/client.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ npm i react-form-action zod-form-data
|
|
|
40
40
|
#### 1️⃣ Create a Server Action
|
|
41
41
|
|
|
42
42
|
```tsx
|
|
43
|
-
// app/
|
|
43
|
+
// app/subscribe/action.ts
|
|
44
44
|
"use server";
|
|
45
45
|
|
|
46
46
|
import { formAction } from "react-form-action";
|
|
@@ -56,7 +56,7 @@ export const subscribeAction = formAction
|
|
|
56
56
|
#### 2️⃣ Create a Client Form Component
|
|
57
57
|
|
|
58
58
|
```tsx
|
|
59
|
-
// app/
|
|
59
|
+
// app/subscribe/SubscribeForm.tsx
|
|
60
60
|
"use client";
|
|
61
61
|
|
|
62
62
|
import {
|
|
@@ -107,12 +107,10 @@ function SubmitButton() {
|
|
|
107
107
|
#### 3️⃣ Render the form on a Page
|
|
108
108
|
|
|
109
109
|
```tsx
|
|
110
|
-
// app/
|
|
110
|
+
// app/subscribe/page.tsx
|
|
111
111
|
|
|
112
112
|
import { SubscribeForm } from "./SubscribeForm";
|
|
113
113
|
|
|
114
|
-
function SuccessMessage() {}
|
|
115
|
-
|
|
116
114
|
export function Page() {
|
|
117
115
|
return <SubscribeForm />;
|
|
118
116
|
}
|
package/dist/client.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default, { PropsWithChildren,
|
|
2
|
+
import React__default, { PropsWithChildren, JSX } from 'react';
|
|
3
3
|
import { b as FormAction, A as ActionState, a as InitialState, I as InvalidState, F as FailureState, S as SuccessState } from './createFormAction-277e6e21.js';
|
|
4
4
|
import { ZodFormattedError } from 'zod';
|
|
5
5
|
import { RenderProp } from 'react-render-prop-type';
|
|
@@ -33,7 +33,7 @@ type SpreadActionContext<Data = unknown, Error = unknown, ValidationError = unkn
|
|
|
33
33
|
declare function useActionContext<Data, Error, ValidationError>(action?: FormAction<Data, Error, ValidationError>): SpreadActionContext<Data, Error, ValidationError>;
|
|
34
34
|
declare function Action<Data, Error, ValidationError>({ children, action: formAction, initialData, permalink, }: ActionProps<Data, Error, ValidationError>): React__default.JSX.Element;
|
|
35
35
|
|
|
36
|
-
type
|
|
36
|
+
type FormProps = Omit<JSX.IntrinsicElements["form"], "action"> & {
|
|
37
37
|
/**
|
|
38
38
|
* Opt-in into automatic form reset by using the form "action" prop.
|
|
39
39
|
* By default, the onSubmit with a custom transition which opts-out of the implicit form reset.
|
|
@@ -42,7 +42,7 @@ type ActionFormProps = Omit<FormHTMLAttributes<HTMLFormElement>, "action"> & {
|
|
|
42
42
|
*/
|
|
43
43
|
autoReset?: boolean;
|
|
44
44
|
};
|
|
45
|
-
declare function
|
|
45
|
+
declare function Form({ autoReset, ...props }: FormProps): JSX.Element;
|
|
46
46
|
|
|
47
47
|
declare const SEPARATOR: ".";
|
|
48
48
|
type Paths<Err> = {
|
|
@@ -73,4 +73,4 @@ declare function FormStatus({ children, }: RenderProp<ReturnType<typeof useFormS
|
|
|
73
73
|
*/
|
|
74
74
|
declare function Pending({ children }: PropsWithChildren): React.ReactNode;
|
|
75
75
|
|
|
76
|
-
export { Action, ActionContextState,
|
|
76
|
+
export { Action, ActionContextState, ActionProps, Form, FormProps, FormStatus, InferZodErrorPaths, Paths, Pending, ZodFieldError, ZodFieldErrorProps, createComponents, useActionContext };
|
package/dist/client.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{a 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 S}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 v({children:t,action:o,initialData:e,permalink:n}){let[r,i,s]=S(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 y,{startTransition as A}from"react";function V({autoReset:t=!1,...o}){let{action:e}=a();return y.createElement("form",{...t?{action:e}:{onSubmit:r=>{r.preventDefault();let i=r.currentTarget;A(()=>{e(new FormData(i))})}},...o})}import h from"react";import l from"react";var F=".",P=Object.freeze({_errors:Object.freeze([])});function u({errors:t,name:o="",children:e=({errors:n})=>l.createElement(l.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&&h.createElement(u,{errors:r,name:e})}return{FieldError:o}}import{useFormStatus as C}from"react-dom";function X({children:t}){return t(C())}function q({children:t}){let{isPending:o}=a();return o&&t}export{v as Action,V as Form,X as FormStatus,q as Pending,u as ZodFieldError,$ as createComponents,a as useActionContext};
|