Files
documentation/node_modules/@docusaurus/theme-common/lib/utils/reactUtils.d.ts
2024-03-22 03:47:51 +05:30

60 lines
2.3 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { type ComponentType, type ReactNode } from 'react';
/**
* Temporary userland implementation until an official hook is implemented
* See RFC: https://github.com/reactjs/rfcs/pull/220
*
* Permits to transform an unstable callback (like an arrow function provided as
* props) to a "stable" callback that is safe to use in a `useEffect` dependency
* array. Useful to avoid React stale closure problems + avoid useless effect
* re-executions.
*
* This generally works but has some potential drawbacks, such as
* https://github.com/facebook/react/issues/16956#issuecomment-536636418
*/
export declare function useEvent<T extends (...args: never[]) => unknown>(callback: T): T;
/**
* Gets `value` from the last render.
*/
export declare function usePrevious<T>(value: T): T | undefined;
/**
* This error is thrown when a context is consumed outside its provider. Allows
* reusing a generic error message format and reduces bundle size. The hook's
* name will be extracted from its stack, so only the provider's name is needed.
*/
export declare class ReactContextError extends Error {
constructor(providerName: string, additionalInfo?: string);
}
/**
* Shallow-memoize an object. This means the returned object will be the same as
* the previous render if the property keys and values did not change. This
* works for simple cases: when property values are primitives or stable
* objects.
*
* @param obj
*/
export declare function useShallowMemoObject<O extends object>(obj: O): O;
type SimpleProvider = ComponentType<{
children: ReactNode;
}>;
/**
* Creates a single React provider from an array of existing providers
* assuming providers only take "children" as props.
*
* Prevents the annoying React element nesting
* Example here: https://getfrontend.tips/compose-multiple-react-providers/
*
* The order matters:
* - The first provider is at the top of the tree.
* - The last provider is the most nested one
*
* @param providers array of providers to compose
*/
export declare function composeProviders(providers: SimpleProvider[]): SimpleProvider;
export {};
//# sourceMappingURL=reactUtils.d.ts.map