From 3554f79449c39b71336a0cfceda9b38b0e0ea629 Mon Sep 17 00:00:00 2001 From: nmccready Date: Wed, 26 Jun 2019 16:58:48 -0400 Subject: [PATCH] fix: useMap uses prevMap state which is safer --- src/useMap.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/useMap.ts b/src/useMap.ts index 749ac656e9..ae1ffa9658 100644 --- a/src/useMap.ts +++ b/src/useMap.ts @@ -15,10 +15,10 @@ const useMap = (initialMap: T = {} as T): [T, Actions { get: (key: keyof T) => map[key as string], set: (key: K, entry: T[K]) => { - set({ - ...map, + set((prevMap)=>({ + ...prevMap, [key]: entry, - }); + })); }, remove: (key: keyof T) => { const { [key]: omit, ...rest } = map;