@wordpress/data
Version:
Data module for WordPress.
26 lines • 844 B
TypeScript
/**
* External dependencies
*/
import type { AnyAction, Reducer } from 'redux';
/**
* Higher-order reducer creator which creates a combined reducer object, keyed
* by a property on the action object.
*
* @param actionProperty Action property by which to key object.
* @return Higher-order reducer.
*
* @example
* ```js
* import { keyedReducer } from '@wordpress/data';
*
* const itemsByContext = keyedReducer( 'context' )( ( state = [], action ) => {
* switch ( action.type ) {
* case 'ADD_ITEM':
* return [ ...state, action.item ];
* }
* return state;
* } );
* ```
*/
export declare const keyedReducer: <TState extends unknown, TAction extends AnyAction>(actionProperty: string) => (reducer: Reducer<TState, TAction>) => Reducer<Record<string, TState>, TAction>;
//# sourceMappingURL=keyed-reducer.d.ts.map