Skip to content

Support react@canary release #101

Description

@ellemedit

React have plans to add new valid element/node type, hooks and APIs as react canary released.
I summarized that required for upcoming react canary things. Can we support these?

New React hooks and APIs are:

  • use: (promise<'value> | context<'value>) => 'value
    • I would suggest new type valueContainer<'value> to express above as they defined value container in RFC.
    • TypeScript type binding
  • cache: 'value => 'value
    • next.js docs
    • TypeScript: export function cache<CachedFunction extends Function>(fn: CachedFunction): CachedFunction
  • useTransition (already bound, just ignore)
  • useDeferredValue (already bound, just ignore)
  • startTransition: ((. unit => unit) => unit)

New ReactDOM hooks and APIs are:

Client Action Function Support: string | (formData: FormData) => unit

  • <button formAction={(formData) => { ... }} />
  • <form action={(formData) => { ... }} />

Async component:

rescript input:

typeuser= {id: string, name: string}
letfetchUserById=async (userId) => {
{
id: userId,
name: Js.Float.toStringWithRadix(Js.Math.random(), ~radix=16),
}
}
@react.componentletmake=async (~userId) => {
letuser=awaitfetchUserById(userId)
<div> {React.string(user.name)} </div>
}

Async component JS output expectation:

import*asJsxRuntimefrom"react/jsx-runtime";asyncfunctionfetchUserById(userId){return{id: userId,name: Math.random().toString(16)};}asyncfunctionPlayground(props){varuser=awaitfetchUserById(props.userId);returnJsxRuntime.jsx("div",{children: user.name});}varmake=Playground;export{fetchUserById,make};

New valid node:

Promise node:

typeuser= {id: string, name: string}
letfetchUserById=async (userId) => {
{
id: userId,
name: Js.Float.toStringWithRadix(Js.Math.random(), ~radix=16),
}
}
letfetchUserNameById=async (userId) => {
letuser=awaitfetchUserById(userId)
user.name
}
@react.componentletmake= (~userId) => {
letuserName=fetchUserNameById(userId)
<React.Suspense>
{React.promise(userName)}
</React.Suspense>
}

expect output:

import*asReactfrom"react";import*asJsxRuntimefrom"react/jsx-runtime";asyncfunctionfetchUserById(userId){return{id: userId,name: Math.random().toString(16)};}asyncfunctionfetchUserNameById(userId){return(awaitfetchUserById(userId)).name;}functionPlayground(props){varuserName=fetchUserNameById(props.userId);returnJsxRuntime.jsx(React.Suspense,{children: userName});}varmake=Playground;export{fetchUserById,fetchUserNameById,make};

React.Context node


thank you for reading this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions