Options
All
  • Public
  • Public/Protected
  • All
Menu

Restash

Index

Type aliases

ActionTypes: keyof typeof Action
DeepPartial<T>: { [ K in keyof T]?: T[K] extends infer R[] ? DeepPartial<R>[] : DeepPartial<T[K]> }

Type parameters

  • T

DefaultStatusTypes: keyof typeof DefaultStatus
Dispatch<S, U>: (state: S, status?: U) => S

Type parameters

  • S

  • U: string

Type declaration

    • (state: S, status?: U): S
    • Default dispactch type/interface.

      Parameters

      • state: S
      • Optional status: U

      Returns S

KeyOf<T>: Extract<keyof T, string>

Type parameters

  • T

Middleware: <S, U>(store: IRestash<S, U>) => (next: Dispatch<S, U>) => (payload: any) => S

Type declaration

    • Interface/type for middlware.

      Type parameters

      • S

      • U: string

      Parameters

      Returns (next: Dispatch<S, U>) => (payload: any) => S

        • (next: Dispatch<S, U>): (payload: any) => S
        • Parameters

          Returns (payload: any) => S

            • (payload: any): S
            • Parameters

              • payload: any

              Returns S

MiddlewareDispatch: <S, U>(state: S, status?: U) => S

Type declaration

    • <S, U>(state: S, status?: U): S
    • Intermediary type for middleware dispatch.

      Type parameters

      • S

      • U: string

      Parameters

      • state: S
      • Optional status: U

      Returns S

Path<T>: ParsePathKey<T> extends string | keyof T ? ParsePathKey<T> : keyof T

Type parameters

  • T

PathValue<T, P>: P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Rest extends Path<T[Key]> ? PathValue<T[Key], Rest> : never : never : P extends keyof T ? T[P] : never

Type parameters

RestashHook<S, U, D>: [S, D, IRestash<S, U, D>]

The type/interface for the exposed Restash hook.

Type parameters

StatusBaseTypes: keyof typeof StatusBase

Functions

  • createContext<S, A>(options: IContextOptions<S, A>): { Consumer: Consumer<[S, Dispatch<A>]>; Context: Context<[S, Dispatch<A>]>; Provider: (__namedParameters: IProvider<S, A>) => Element }
  • Creates a context for persisting data in your application, createContext is used by both createStore and createRestash.

    example

    const store = createContext<S, A>({ initialState: options.initialState, reducer: options.reducer });

    Type parameters

    Parameters

    Returns { Consumer: Consumer<[S, Dispatch<A>]>; Context: Context<[S, Dispatch<A>]>; Provider: (__namedParameters: IProvider<S, A>) => Element }

    • Consumer: Consumer<[S, Dispatch<A>]>
    • Context: Context<[S, Dispatch<A>]>
    • Provider: (__namedParameters: IProvider<S, A>) => Element
        • (__namedParameters: IProvider<S, A>): Element
        • Parameters

          Returns Element

  • Creates Restash store instance with simple opinionated reducer for typical persistent tasks.

    example

    import { createRestash } from 'restash'; const { useStore } = createRestash({ initialState: {}, persist: 'MyApp' }); const App = () => { const [state, dispatch, restash] = useStore(); return (

         {JSON.stringify(state, null, 2)}
       
    ); };

    Type parameters

    • S: Record<string, any>

    • U: string = "start" | "progress" | "error" | "complete"

    Parameters

    • Optional options: IRestashOptions<S, U>

      options used to initialize Restash.

    Returns { Consumer: Consumer<[State, Dispatch<IRestashAction<"data", any>>]>; Context: Context<[State, Dispatch<IRestashAction<"data", any>>]>; Provider: (__namedParameters: IProvider<State, IRestashAction<"data", any>>) => Element; clearPersistence: { <K>(...keys: K[]): boolean; (...keys: string[]): boolean }; useStore: { <K>(key: K, value?: any): RestashHook<PathValue<S, K>, U>; (): RestashHook<S, U> } }

    • Consumer: Consumer<[State, Dispatch<IRestashAction<"data", any>>]>
    • Context: Context<[State, Dispatch<IRestashAction<"data", any>>]>
    • Provider: (__namedParameters: IProvider<State, IRestashAction<"data", any>>) => Element
    • clearPersistence: { <K>(...keys: K[]): boolean; (...keys: string[]): boolean }
        • <K>(...keys: K[]): boolean
        • (...keys: string[]): boolean
        • Clears persistence, when keys are present clears only those persisted keys.

          Type parameters

          • K: string | number | symbol | `${string}.${string}`

          Parameters

          • Rest ...keys: K[]

            keys that should be cleared.

          Returns boolean

        • Clears persistence, when keys are present clears only those persisted keys.

          Parameters

          • Rest ...keys: string[]

            keys that should be cleared.

          Returns boolean

    • useStore: { <K>(key: K, value?: any): RestashHook<PathValue<S, K>, U>; (): RestashHook<S, U> }
        • Constrains store hook to a specific key.

          Type parameters

          • K: string | number | symbol | `${string}.${string}`

          Parameters

          • key: K

            the store key to constrain hook at.

          • Optional value: any

            the default value for the key.

          Returns RestashHook<PathValue<S, K>, U>

        • The default store hook.

          Returns RestashHook<S, U>

  • createStore<S, A>(options?: IStoreOptions<S, A>): { Consumer: Consumer<[S, Dispatch<A>]>; Context: Context<[S, Dispatch<A>]>; Provider: (__namedParameters: IProvider<S, A>) => Element; useStore: () => [S, Dispatch<A>] }
  • Creates store using default or provided reducer and dispatch action which contains one property "payload" for your data.

    example

    import { createStore } from 'restash'; const { useStore } = createStore({ initialState: {} }); const App = () => { const [state, dispatch] = useStore(); return (

         {JSON.stringify(state, null, 2)}
       
    ); };

    Type parameters

    Parameters

    • Optional options: IStoreOptions<S, A>

      base options to initialize context.

    Returns { Consumer: Consumer<[S, Dispatch<A>]>; Context: Context<[S, Dispatch<A>]>; Provider: (__namedParameters: IProvider<S, A>) => Element; useStore: () => [S, Dispatch<A>] }

    • Consumer: Consumer<[S, Dispatch<A>]>
    • Context: Context<[S, Dispatch<A>]>
    • Provider: (__namedParameters: IProvider<S, A>) => Element
        • (__namedParameters: IProvider<S, A>): Element
        • Parameters

          Returns Element

    • useStore: () => [S, Dispatch<A>]
        • (): [S, Dispatch<A>]
        • Returns [S, Dispatch<A>]

  • Type parameters

    • Y: { head: string; next: string; prev: string; stat: string } = { head: string; next: string; prev: string; stat: string }

    Parameters

    • Optional styles: Partial<Y>

    Returns Middleware

Generated using TypeDoc