0.3.3 • Published 6 months ago

@types/use-global-hook v0.3.3

Weekly downloads
2,973
License
MIT
Repository
github
Last release
6 months ago

Installation

npm install --save @types/use-global-hook

Summary

This package contains type definitions for use-global-hook (https://github.com/andregardi/use-global-hook#readme).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/use-global-hook.

index.d.ts

// Type definitions for use-global-hook 0.1
// Project: https://github.com/andregardi/use-global-hook#readme
// Definitions by: James Hong <https://github.com/ojameso>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.6

import Immer from 'immer';

// Use an interface so that different versions of React can be used
interface ReactInterface {
    useEffect: (...args: any[]) => any;
    useState: (...args: any[]) => any;
    useMemo: (...args: any[]) => any;
}
// to ignore strict-export-declare-modifiers error
export {};

// Where S is typeof state and A is typeof associated actions
export interface Store<S, A> {
    state: S;
    actions: A;
    setState(state: S, afterUpdateCallback?: () => void): void;
}

type IProduce = typeof Immer;
export type InitializerFunction<S, A> = (store: Store<S, A>) => void;

export interface Options<S, A> {
    Immer?: IProduce | undefined;
    initializer?: InitializerFunction<S, A> | undefined;
}

type UseGlobal<S, A> = (() => [S, A]) &
    (<NS>(stateFunc: (state: S) => NS) => [NS, A]) &
    (<NS, NA>(stateFunc: (state: S) => NS, actionsFunc: (state: A) => NA) => [NS, NA]) &
    (<NA>(stateFunc: undefined, actionsFunc: (state: A) => NA) => [S, NA]);

// The option property also has an initializer function type for backward compatibility with 0.1.2
// see https://github.com/andregardi/use-global-hook/pull/51/files#diff-5330e30faa98f2945d75901849861a10R4
export default function useStore<S, A>(
    React: ReactInterface,
    inititalState: S,
    actions: object,
    options?: Options<S, A> | InitializerFunction<S, A>,
): UseGlobal<S, A>;

Additional Details

  • Last updated: Mon, 15 Nov 2021 16:31:22 GMT
  • Dependencies: @types/immer
  • Global values: none

Credits

These definitions were written by James Hong.

0.3.0

10 months ago

0.3.2

7 months ago

0.3.1

8 months ago

0.3.3

6 months ago

0.1.5

2 years ago

0.1.4

3 years ago

0.1.3

4 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago