Skip to content

React 19 APIs #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
bloodyowl authored and cknitt committed May 3, 2025
commit 1694f228fdcee4bdf57ec05111ea6a857aa6e33d
3 changes: 0 additions & 3 deletions src/React.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions src/React.res
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ external useCallback7: ('callback, ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => 'callback =
@module("react")
external useContext: Context.t<'any> => 'any = "useContext"

@module("react")
external usePromise: promise<'a> => 'a = "use"

@module("react") external useRef: 'value => ref<'value> = "useRef"

@module("react")
Expand Down Expand Up @@ -433,17 +436,6 @@ external useActionState: (
external useOptimistic: ('state, ('state, 'action) => 'state) => ('state, 'action => unit) =
"useOptimistic"

module Usable = {
type t<'value>

external context: Context.t<'value> => t<'value> = "%identity"
external promise: promise<'value> => t<'value> = "%identity"
}

/** `use` is a React API that lets you read the value of a resource like a Promise or context. */
@module("react")
external use: Usable.t<'value> => 'value = "use"

/** `act` is a test helper to apply pending React updates before making assertions. */
@module("react")
external act: (unit => promise<unit>) => promise<unit> = "act"