UNPKG

@toolpad/utils

Version:

Shared utilities used by Toolpad packages.

30 lines 1.36 kB
import * as React from 'react'; /** * Like `Array.prototype.join`, but for React nodes. */ export declare function interleave(items: React.ReactNode[], separator: React.ReactNode): React.ReactNode; /** * Consume a context but throw when used outside of a provider. */ export declare function useNonNullableContext<T>(context: React.Context<T>, name?: string): NonNullable<T>; /** * Context that throws when used outside of a provider. */ export declare function createProvidedContext<T>(name?: string): [() => T, React.ComponentType<React.ProviderProps<T>>]; export declare function useAssertedContext<T>(context: React.Context<T | undefined>): T; /** * Debugging tool that logs updates to props. */ export declare function useTraceUpdates<P extends object>(prefix: string, props: P): void; export default function getComponentDisplayName(Component: React.ComponentType<any> | string): string; /** * Create a shared state to be used across the application. Returns a useState hook that * is synchronized on the same state between all instances where it is called. */ export declare function createGlobalState<T>(initialState: T): { getState: () => T; setState: (newState: T | ((oldValue: T) => T)) => void; useValue: () => T; useState: () => [T, React.Dispatch<React.SetStateAction<T>>]; subscribe: (cb: (state: T) => void) => () => void; };