import React from 'react' import {Store, Event, Effect, Domain, Scope, EventCallable} from 'effector' export const Provider: React.Provider export type StoreConsumer = React.ComponentType<{ children: (state: State) => React.ReactNode }> export type Gate = React.ComponentType & { open: EventCallable close: EventCallable status: Store state: Store } export type StoreView = React.ComponentType & { mounted: Event<{props: Props; state: State}> unmounted: Event<{props: Props; state: State}> } /** * @deprecated use useUnit hook instead */ export function useStore( store: Store, opts?: {forceScope?: boolean}, ): State export function useStoreMap< State, Result, Keys extends [any] | ReadonlyArray | any[], >(opts: { readonly store: Store readonly keys: Keys readonly fn: (state: State, keys: Keys) => Result | undefined readonly updateFilter?: (update: Result, current: Result) => boolean readonly defaultValue: Result readonly forceScope?: boolean }): Result export function useStoreMap< State, Result, Keys extends [any] | ReadonlyArray | any[], >(opts: { readonly store: Store readonly keys: Keys readonly fn: (state: State, keys: Keys) => Result readonly updateFilter?: (update: Result, current: Result) => boolean readonly forceScope?: boolean }): Result export function useStoreMap( store: Store, fn: (state: State) => Result, ): Result export function useList( list: Store | Store>, renderItem: { readonly keys?: any[] readonly fn: (item: T, key: Key) => React.ReactNode readonly getKey: (item: T) => Key readonly placeholder?: React.ReactNode }, {forceScope}?: {forceScope?: boolean}, ): React.ReactNode export function useList( list: Store | Store>, renderItem: | { readonly keys?: any[] readonly fn: (item: T, index: number) => React.ReactNode readonly placeholder?: React.ReactNode } | ((item: T, index: number) => React.ReactNode), {forceScope}?: {forceScope?: boolean}, ): React.ReactNode export function useGate(Gate: Gate, props?: Props): void export function createGate(name?: string): Gate export function createGate(config: { defaultState?: Props name?: string domain?: Domain sid?: string }): Gate export function createGate( name: string, defaultState: Props, ): Gate /** * @deprecated use useUnit hook instead */ export function createComponent( store: Store, view: (props: Props, state: State) => React.ReactNode, ): StoreView /** * @deprecated use useUnit hook instead */ export function createComponent( store: Shape, view: ( props: Props, state: {[K in keyof Shape]: Shape[K] extends Store ? U : Shape[K]}, ) => React.ReactNode, ): StoreView< {[K in keyof Shape]: Shape[K] extends Store ? U : Shape[K]}, Props > /** * @deprecated use useUnit hook instead */ export function connect< State extends object, Com extends React.ComponentType, >(store: Store): (Component: Com) => React.ComponentType /** * @deprecated use useUnit hook instead */ export function connect< State extends object, Com extends React.ComponentType, >(Component: Com): (store: Store) => React.ComponentType /** * @deprecated use useUnit hook instead */ export function createStoreConsumer( store: Store, ): StoreConsumer /** * @deprecated use useUnit hook instead */ export function useEvent( event: EventCallable, opts?: {forceScope?: boolean}, ): () => void /** * @deprecated use useUnit hook instead */ export function useEvent( event: EventCallable, opts?: {forceScope?: boolean}, ): (payload: T) => T /** * @deprecated use useUnit hook instead */ export function useEvent( fx: Effect, opts?: {forceScope?: boolean}, ): () => Promise /** * @deprecated use useUnit hook instead */ export function useEvent( fx: Effect, opts?: {forceScope?: boolean}, ): (payload: T) => Promise /** * @deprecated use useUnit hook instead */ export function useEvent | Effect)[]>( list: [...List], opts?: {forceScope?: boolean}, ): { [Key in keyof List]: List[Key] extends EventCallable ? (payload: T) => T : List[Key] extends Effect ? (payload: P) => Promise : never } /** * @deprecated use useUnit hook instead */ export function useEvent< Shape extends Record | Effect>, >( shape: Shape, opts?: {forceScope?: boolean}, ): { [Key in keyof Shape]: Shape[Key] extends EventCallable ? (payload: T) => T : Shape[Key] extends Effect ? (payload: P) => Promise : never } type Equal = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? true : false export function useUnit( store: Store, opts?: {forceScope?: boolean}, ): State export function useUnit( event: EventCallable, opts?: {forceScope?: boolean}, ): () => void export function useUnit( event: EventCallable, opts?: {forceScope?: boolean}, ): (payload: T) => T export function useUnit( fx: Effect, opts?: {forceScope?: boolean}, ): () => Promise export function useUnit( fx: Effect, opts?: {forceScope?: boolean}, ): (payload: T) => Promise export function useUnit< List extends (EventCallable | Effect | Store)[], >( list: [...List], opts?: {forceScope?: boolean}, ): { [Key in keyof List]: List[Key] extends EventCallable ? Equal extends true ? () => void : (payload: T) => T : List[Key] extends Effect ? Equal extends true ? () => Promise : (payload: P) => Promise : List[Key] extends Store ? V : never } export function useUnit< Shape extends Record | Effect | Store>, >( shape: Shape | {'@@unitShape': () => Shape}, opts?: {forceScope?: boolean}, ): { [Key in keyof Shape]: Shape[Key] extends EventCallable ? Equal extends true ? () => void : (payload: T) => T : Shape[Key] extends Effect ? Equal extends true ? () => Promise : (payload: P) => Promise : Shape[Key] extends Store ? V : never } /** * **Low-Level API for library developers.** * For production code usage **prefer `useUnit` hook instead**. * * React hook, which returns current scope or null if no scope provided via `Provider`. */ export function useProvidedScope(): Scope | null