UNPKG

2.5 kBTypeScriptView Raw
1import type { AnyFramework, DecoratorApplicator, StoryContext, StoryId, Args } from '@storybook/csf';
2interface Hook {
3 name: string;
4 memoizedState?: any;
5 deps?: any[] | undefined;
6}
7interface Effect {
8 create: () => (() => void) | void;
9 destroy?: (() => void) | void;
10}
11declare type AbstractFunction = (...args: any[]) => any;
12export declare class HooksContext<TFramework extends AnyFramework> {
13 hookListsMap: WeakMap<AbstractFunction, Hook[]>;
14 mountedDecorators: Set<AbstractFunction>;
15 prevMountedDecorators: Set<AbstractFunction>;
16 currentHooks: Hook[];
17 nextHookIndex: number;
18 currentPhase: 'MOUNT' | 'UPDATE' | 'NONE';
19 currentEffects: Effect[];
20 prevEffects: Effect[];
21 currentDecoratorName: string | null;
22 hasUpdates: boolean;
23 currentContext: StoryContext<TFramework> | null;
24 renderListener: (storyId: StoryId) => void;
25 constructor();
26 init(): void;
27 clean(): void;
28 getNextHook(): Hook;
29 triggerEffects(): void;
30 addRenderListeners(): void;
31 removeRenderListeners(): void;
32}
33export declare const applyHooks: <TFramework extends AnyFramework>(applyDecorators: DecoratorApplicator<TFramework, Args>) => DecoratorApplicator<TFramework, Args>;
34export declare function useMemo<T>(nextCreate: () => T, deps?: any[]): T;
35export declare function useCallback<T>(callback: T, deps?: any[]): T;
36export declare function useRef<T>(initialValue: T): {
37 current: T;
38};
39export declare function useState<S>(initialState: (() => S) | S): [S, (update: ((prevState: S) => S) | S) => void];
40export declare function useReducer<S, A>(reducer: (state: S, action: A) => S, initialState: S): [S, (action: A) => void];
41export declare function useReducer<S, I, A>(reducer: (state: S, action: A) => S, initialArg: I, init: (initialArg: I) => S): [S, (action: A) => void];
42export declare function useEffect(create: () => (() => void) | void, deps?: any[]): void;
43export interface Listener {
44 (...args: any[]): void;
45}
46export interface EventMap {
47 [eventId: string]: Listener;
48}
49export declare function useChannel(eventMap: EventMap, deps?: any[]): any;
50export declare function useStoryContext<TFramework extends AnyFramework>(): StoryContext<TFramework>;
51export declare function useParameter<S>(parameterKey: string, defaultValue?: S): S | undefined;
52export declare function useArgs(): [Args, (newArgs: Args) => void, (argNames?: [string]) => void];
53export declare function useGlobals(): [Args, (newGlobals: Args) => void];
54export {};