@instructure/ui-react-utils
Version:
A React utility library made by Instructure Inc.
24 lines • 1.25 kB
TypeScript
import { ComponentClass } from 'react';
type WithDeterministicIdProps = {
deterministicId?: (instanceName?: string) => string;
};
/**
* This decorator injects a `deterministicId` prop into the decorated class,
* used to generate SSR-safe, hydration-stable ids.
*
* It is backed by React's built-in {@link https://react.dev/reference/react/useId `useId`},
* which produces the same id on the server and the client for a given position
* in the React tree The injected `deterministicId(instanceName?)` function may
* be called multiple times with distinct `instanceName` values to derive
* several unique, stable ids from the same component instance.
*
* Note: for apps that mount more than one independent React root on the same
* page (including module federation), pass a distinct `identifierPrefix` to each
* `createRoot`/`hydrateRoot` call so ids stay unique across roots.
* Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
*/
declare const withDeterministicId: (...args: unknown[]) => (ComposedComponent: ComponentClass<any>) => any;
export default withDeterministicId;
export { withDeterministicId };
export type { WithDeterministicIdProps };
//# sourceMappingURL=withDeterministicId.d.ts.map