Skip to content

Commit

Permalink
Add useOptimistic
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Jul 16, 2024
1 parent 39189e0 commit b869bd3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/React.re
Original file line number Diff line number Diff line change
Expand Up @@ -887,4 +887,28 @@ module Experimental = {
/* This module is used to bind to APIs for future versions of React. There is no guarantee of backwards compatibility or stability. */

[@mel.module "react"] external use: Js.Promise.t('a) => 'a = "use";

module FormData = {
/* TODO: Add FormData type to melange.js */
type t;
};

type formatStatus = {
pending: bool,
data: FormData.t,
[@mel.as "method"]
method_: [ | `get | `post],
/* action: Js.Nullable.t(fn), */
};

/* https://es.react.dev/reference/react/useOptimistic */
[@mel.module "react"]
external useOptimistic:
('state, ('state, 'optimisticValue) => 'state) =>
('state, 'optimisticValue => unit) =
"useOptimistic";

/* https://react.dev/reference/react-dom/hooks/useFormStatus#use-form-status */
[@mel.module "react"]
external useFormStatus: unit => formatStatus = "useFormStatus";
};
7 changes: 7 additions & 0 deletions src/React.rei
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,14 @@ external useTransitionAsync:

module Experimental: {
/* This module is used to bind to APIs for future versions of React. There is no guarantee of backwards compatibility or stability. */

[@mel.module "react"] external use: Js.Promise.t('a) => 'a = "use";

[@mel.module "react"]
external useOptimistic:
('state, ('state, 'optimisticValue) => 'state) =>
('state, 'optimisticValue => unit) =
"useOptimistic";
};

[@mel.set]
Expand Down

0 comments on commit b869bd3

Please sign in to comment.