Skip to content

Commit

Permalink
fix: useMap uses prevMap state which is safer
Browse files Browse the repository at this point in the history
  • Loading branch information
nmccready committed Jun 26, 2019
1 parent ba6d375 commit 3554f79
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/useMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const useMap = <T extends object = any>(initialMap: T = {} as T): [T, Actions<T>
{
get: (key: keyof T) => map[key as string],
set: <K extends keyof T>(key: K, entry: T[K]) => {
set({
...map,
set((prevMap)=>({
...prevMap,
[key]: entry,
});
}));
},
remove: (key: keyof T) => {
const { [key]: omit, ...rest } = map;
Expand Down

0 comments on commit 3554f79

Please sign in to comment.