28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
|
/**
|
|||
|
* Traverses up the React fiber tree to find the StrictMode component.
|
|||
|
* Note: This only detects strict mode from React >= 18
|
|||
|
* https://github.com/reactwg/react-18/discussions/19
|
|||
|
* @returns If strict mode is being used in the React tree
|
|||
|
*/
|
|||
|
declare const useIsStrictMode: () => boolean;
|
|||
|
|
|||
|
/**
|
|||
|
* A factory that returns the disposable instance and it's dispose function
|
|||
|
*/
|
|||
|
type DisposableFactory<TInstance> = () => [TInstance, () => void];
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a disposable instance during **render time** that will
|
|||
|
* be created once (based on dependency array) even during strict mode.
|
|||
|
* The disposable will be disposed based on the dependency array similar to
|
|||
|
* useEffect.
|
|||
|
*
|
|||
|
* ⚠️ This can only be called **once** per component
|
|||
|
* @param factory - factory for disposable and its dispose function
|
|||
|
* @param deps - Similar to a React dependency array
|
|||
|
* @returns - The disposable instance
|
|||
|
*/
|
|||
|
declare function useDisposable<TInstance>(factory: DisposableFactory<TInstance>, deps: any[]): TInstance | null;
|
|||
|
|
|||
|
export { DisposableFactory, useDisposable, useIsStrictMode };
|