Skip to content

Commit 1694f22

Browse files
bloodyowlcknitt
authored andcommitted
Add usePromise for use(promise)
`use(context)` seems to exactly replicate the `useContext(context)` logic, and we want to maximize retro-compability (ie. not switch from `useContext` to `use` for that under the hood). simply adding `usePromise(promise)` seems to be the simplest, least invasive way to add the functionality.
1 parent 3a53934 commit 1694f22

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

src/React.bs.js

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/React.res

+3-11
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ external useCallback7: ('callback, ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => 'callback =
251251
@module("react")
252252
external useContext: Context.t<'any> => 'any = "useContext"
253253

254+
@module("react")
255+
external usePromise: promise<'a> => 'a = "use"
256+
254257
@module("react") external useRef: 'value => ref<'value> = "useRef"
255258

256259
@module("react")
@@ -433,17 +436,6 @@ external useActionState: (
433436
external useOptimistic: ('state, ('state, 'action) => 'state) => ('state, 'action => unit) =
434437
"useOptimistic"
435438

436-
module Usable = {
437-
type t<'value>
438-
439-
external context: Context.t<'value> => t<'value> = "%identity"
440-
external promise: promise<'value> => t<'value> = "%identity"
441-
}
442-
443-
/** `use` is a React API that lets you read the value of a resource like a Promise or context. */
444-
@module("react")
445-
external use: Usable.t<'value> => 'value = "use"
446-
447439
/** `act` is a test helper to apply pending React updates before making assertions. */
448440
@module("react")
449441
external act: (unit => promise<unit>) => promise<unit> = "act"

0 commit comments

Comments
 (0)