How to use the use-global-hook function in use-global-hook

To help you get started, we’ve selected a few use-global-hook examples, based on popular ways it is used in public projects.

github DefinitelyTyped / DefinitelyTyped / types / use-global-hook / use-global-hook-tests.ts View on Github external
}

type setFunc = (value: string) => void;

interface associatedActionsType {
  setValue: setFunc;
}

const initializer: InitializerFunction<stateType, associatedActionsType> = (store: Store<stateType, associatedActionsType>) => {
    store.actions.setValue('');
    store.state.value;
    store.setState({ value: 'string' });
};

// with initializer
const store = useStore<stateType, associatedActionsType>(React, { value: '' }, {}, initializer);

// default
store(); // $ExpectType [stateType, associatedActionsType]

// works without passing expected type when using state filter
store((state: stateType) => state.value); // $ExpectType [string, associatedActionsType]
store<string>((state: stateType) => state.value); // $ExpectType [string, associatedActionsType]

// works without passing expected type when using only action filter
store(undefined, (action: associatedActionsType) => action.setValue); // $ExpectType [stateType, setFunc]
// returns expected type if passed types
store<setFunc>(undefined, (action: associatedActionsType) => action.setValue); // $ExpectType [stateType, setFunc]

// works without passing expected type when using both state and action filters
store((state: stateType) => state.value, (actions: associatedActionsType) => actions.setValue); // $ExpectType [string, setFunc]
store<string, setFunc>((state: stateType) => state.value, (actions: associatedActionsType) => actions.setValue); // $ExpectType [string, setFunc]
github DefinitelyTyped / DefinitelyTyped / types / use-global-hook / use-global-hook-tests.ts View on Github external
// works without passing expected type when using state filter
store((state: stateType) => state.value); // $ExpectType [string, associatedActionsType]
store<string>((state: stateType) => state.value); // $ExpectType [string, associatedActionsType]

// works without passing expected type when using only action filter
store(undefined, (action: associatedActionsType) => action.setValue); // $ExpectType [stateType, setFunc]
// returns expected type if passed types
store<setFunc>(undefined, (action: associatedActionsType) => action.setValue); // $ExpectType [stateType, setFunc]

// works without passing expected type when using both state and action filters
store((state: stateType) => state.value, (actions: associatedActionsType) => actions.setValue); // $ExpectType [string, setFunc]
store<string, setFunc>((state: stateType) => state.value, (actions: associatedActionsType) => actions.setValue); // $ExpectType [string, setFunc]

// without initializer
useStore<stateType, associatedActionsType>(React, { value: '' }, {});
github timzprof / book-a-meal / client / src / store / index.js View on Github external
{
          id: 2,
          name: 'Bread & Beans',
          price: 500,
          imageUrl:
            'https://thumbs.dreamstime.com/b/plate-ewa-agoyin-agege-bread-nigerian-staple-meal-consisting-baked-beans-red-palm-oil-stew-sauce-90622030.jpg',
          quantity: 5
        }
      ],
      catering_service: 'Book A Meal Caterer'
    }
  ],
  beingOrdered: null
};

const useGlobal = useGlobalHook(React, initialState, actions);

export default useGlobal;

use-global-hook

Easy state management for react using hooks in less than 1kb.

MIT
Latest version published 1 year ago

Package Health Score

58 / 100
Full package analysis

Popular use-global-hook functions

Similar packages