Skip to content

Commit

Permalink
fix(useMap): remove now also uses prevMap state to not overwrite or l…
Browse files Browse the repository at this point in the history
…ose state
  • Loading branch information
nmccready committed Jun 27, 2019
1 parent 7ce8e4f commit 0a59869
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/useMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ const useMap = <T extends object = any>(initialMap: T = {} as T): [T, Actions<T>
}));
},
remove: (key: keyof T) => {
const { [key]: omit, ...rest } = map;
set(rest as T);
set(prevMap => {
const { [key]: omit, ...rest } = prevMap;
return rest as T;
} );
},
reset: () => set(initialMap),
},
Expand Down

0 comments on commit 0a59869

Please sign in to comment.