Skip to content

Instantly share code, notes, and snippets.

@finreinhard
Created January 4, 2024 13:16
Show Gist options
  • Save finreinhard/ca7f2840affdc49b996713698821549a to your computer and use it in GitHub Desktop.
Save finreinhard/ca7f2840affdc49b996713698821549a to your computer and use it in GitHub Desktop.
import { Dispatch, SetStateAction } from "react";
export const removeFromComplexObject =
<Value, State extends Record<keyof State, Value[]>>(
setState: Dispatch<SetStateAction<State>>,
keyName: keyof State
) =>
(filterOption: Value) =>
setState((currentState) => ({
...currentState,
[keyName]: currentState[keyName].filter((f) => f !== filterOption),
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment