Skip to content

Instantly share code, notes, and snippets.

@pflevy
Last active April 16, 2021 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pflevy/bc555d0e6fa159894ece9316997e3433 to your computer and use it in GitHub Desktop.
Save pflevy/bc555d0e6fa159894ece9316997e3433 to your computer and use it in GitHub Desktop.
export const multipleIdsReducerHandler = (reducerFunction) => (
state = {},
action
) => {
const { internalReducerId } = action;
if (internalReducerId === undefined) return state;
const newState = reducerFunction(
state?.byId?.[internalReducerId] || {},
action
);
if (Object.keys(newState).length === 0) return state;
return {
...state,
byId: {
...state.byId,
[internalReducerId]: { ...newState }
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment