FormidableLabs/react-ssr-prepass

React 18 support useId

MarcGuiselin opened this issue · 0 comments

From: trpc/trpc#1343

The dispatcher in ./src/internals/dispatcher.js is missing react 18's new useId hook.

Implementing useId

As implemented by the react core team, useId currently throws an error in ReactPartialRendererHooks.js So unfortunately, we can't use their implementation and must implement our own.

reactwg/react-18#111 and facebook/react#22644 outline the behavior of useId, originally useOpaqueIdentifier

  • useId is not a hook anymore (Edit: I'm wrong about this. See: #75)
  • useId returns a regular, non-opaque string

Thus, I propose the following:

function useId(): string {
  return 'R:' + (rendererStateRef.current.uniqueID++).toString(36)
}