I have some reducers that are similar, receiving same action, how can I deduplicate the code below?
const gridApiReducer = (state: GridApi, action: { type: string; value: GridApi }) => {
switch (action.type) {
case "UPDATE":
return action.value;
default:
return state;
}
};
const columnApiReducer = (state: ColumnApi, action: { type: string; value: ColumnApi}) => {
switch (action.type) {
case "UPDATE":
return action.value;
default:
return state;
}
};
const [gridApi, setGridApiByDispatch] = useReducer(gridApiReducer, {} as GridApi);
const [columnApi, setColumnApiByDispatch] = useReducer(columnApiReducer, {} as ColumnApi);