UNPKG

@wener/ui

Version:

24 lines (23 loc) 1.19 kB
import React from 'react'; export interface SubscriptionContainerProviderProps<State = void> { initialState: State | (() => State); children: React.ReactNode; } export declare type Equality<T = any> = (a: T, b: T) => boolean; export interface SubscriptionContainer<Value, State = void> { Provider: React.ComponentType<SubscriptionContainerProviderProps<State>>; useContainer: () => Value; useState: () => State; useSelector<TSelected>(selector: (state: State) => TSelected, eq?: Equality): TSelected; useWhenValueChange<TSelected>(selector: (state: State) => TSelected, cb: (s: TSelected) => void, eq?: Equality): any; } export interface SubscriptioHookOptions<State> { getState(): State; setState(s: ((s: State) => State) | State): any; updateState(s: (s: State) => void): any; subscribe(cb: (s: State) => void): () => void; } export declare type SubscriptionHook<State, Value> = (options: SubscriptioHookOptions<State>) => Value; export declare function createSubscriptionContainer<Value, State = void>(useHook: SubscriptionHook<State, Value>, { isEqual }?: { isEqual: (a: any, b: any) => boolean; }): SubscriptionContainer<Value, State>;