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.
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:
(promise<'value> | context<'value>) => 'valuevalueContainer<'value>to express above as they defined value container in RFC.'value => 'valueexport function cache<CachedFunction extends Function>(fn: CachedFunction): CachedFunctionuseTransition(already bound, just ignore)useDeferredValue(already bound, just ignore)((. unit => unit) => unit)New ReactDOM hooks and APIs are:
((. unit => unit) => unit)(unit => { pending: boolean, action: promise<void> | (data: FormData) => unit, method: string, data: FormData })(@uncurry ('state, ('state, 'action) => 'state)) => ('state, ('action) => unit)Statepostfix removed from another PR.Client Action Function Support:
string | (formData: FormData) => unit<button formAction={(formData) => { ... }} /><form action={(formData) => { ... }} />Async component:
rescript input:
Async component JS output expectation:
New valid node:
Promise node:
expect output:
React.Context node
thank you for reading this.