Skip to main content

foundation-redux.actionsfromslices

Home > @genesislcap/foundation-redux > ActionsFromSlices

ActionsFromSlices type

Extracts the bound actions type from an array of slices.

Signature:

export type ActionsFromSlices<S extends SliceArray> = {
[K in S[number]['name']]: {
[ActionKey in keyof Extract<S[number], {
name: K;
}>['actions']]: (payload: FirstParameter<Extract<S[number], {
name: K;
}>['actions'][ActionKey]>) => void;
};
};

References: SliceArray

Remarks

This utility type creates a nested object structure where each slice name maps to its actions. Actions are bound to the store and automatically dispatch when called.

Example

const { actions } = createStore([userSlice, cartSlice], initialState);
// actions.user.setUser({ name: 'John' })
// actions.cart.addItem({ id: 'item1', quantity: 1 })