How to use use-global-hook - 3 common examples

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

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

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 = (store: Store) => {
    store.actions.setValue('');
    store.state.value;
    store.setState({ value: 'string' });
};

// with initializer
const store = useStore(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((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(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((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((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(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((state: stateType) => state.value, (actions: associatedActionsType) => actions.setValue); // $ExpectType [string, setFunc]

// without initializer
useStore(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 3 years ago

Package Health Score

54 / 100
Full package analysis

Popular use-global-hook functions

Similar packages