Skip to content

Commit af4bddb

Browse files
committed
ReactDOM.useFormStatus
1 parent f74a62d commit af4bddb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/ReactDOM.res

+34
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ module Client = {
2525
external hydrateRoot: (Dom.element, React.element) => Root.t = "hydrateRoot"
2626
}
2727

28+
// Very rudimentary form data bindings
29+
module FormData = {
30+
type t
31+
type value
32+
33+
@new external make: unit => t = "FormData"
34+
35+
@send external append: (t, string, ~filename: string=?) => unit = "append"
36+
@send external delete: (t, string) => unit = "delete"
37+
@send external get: (t, string) => option<value> = "get"
38+
@send external getAll: (t, string) => array<value> = "getAll"
39+
@send external set: (string, string) => unit = "set"
40+
@send external has: string => bool = "has"
41+
// @send external keys: t => Iterator.t<string> = "keys";
42+
// @send external values: t => Iterator.t<value> = "values";
43+
}
44+
2845
@module("react-dom")
2946
external createPortal: (React.element, Dom.element) => React.element = "createPortal"
3047

@@ -43,6 +60,23 @@ module Ref = {
4360
external callbackDomRef: callbackDomRef => domRef = "%identity"
4461
}
4562

63+
// Hooks
64+
65+
type formStatus<'state> = {
66+
/** If true, this means the parent <form> is pending submission. Otherwise, false. */
67+
pending: bool,
68+
/** An object implementing the FormData interface that contains the data the parent <form> is submitting. If there is no active submission or no parent <form>, it will be null. */
69+
data: FormData.t,
70+
/** This represents whether the parent <form> is submitting with either a GET or POST HTTP method. By default, a <form> will use the GET method and can be specified by the method property. */
71+
method: [#get | #post],
72+
/** A reference to the function passed to the action prop on the parent <form>. If there is no parent <form>, the property is null. If there is a URI value provided to the action prop, or no action prop specified, status.action will be null. */
73+
action: React.action<'state, FormData.t>,
74+
}
75+
76+
/** `useFormStatus` is a Hook that gives you status information of the last form submission. */
77+
@module("react-dom")
78+
external useFormStatus: unit => formStatus<'state> = "useFormStatus"
79+
4680
// Resource Preloading APIs
4781

4882
/** The CORS policy to use. */

0 commit comments

Comments
 (0)