Skip to content

Hook useSingleton() ​

useSingleton<T>(create: () => T): T

Source: singleton.ts

Returns a stable value that is instantiated only once. Useful for classes or objects that should not be re-created on every render.

Type Parameters ​

T ​

T

Parameters ​

create ​

() => T

A factory function that returns the singleton instance.

Returns ​

T

Example ​

ts
const systemManager = useSingleton(() => new SystemManager(systemManagerParams));

Built by Prozilla