Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
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]
// 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: '' }, {});
{
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;