diff --git a/src/useMap.ts b/src/useMap.ts index 85a83b5a31..a0c60e9662 100644 --- a/src/useMap.ts +++ b/src/useMap.ts @@ -27,7 +27,7 @@ const useMap = (initialMap: T = {} as T): [T, Actions }, reset: () => set(initialMap), }), - [set] + [map, set] ); return [map, utils]; diff --git a/tests/useMap.test.ts b/tests/useMap.test.ts index 1c238e12c3..58623f6bc4 100644 --- a/tests/useMap.test.ts +++ b/tests/useMap.test.ts @@ -22,7 +22,7 @@ it('should init empty map if not initial object provided', () => { expect(result.current[0]).toEqual({}); }); -it('should get corresponding value for existing provided key', () => { +it('should get corresponding value for initial provided key', () => { const { result } = setUp({ foo: 'bar', a: 1 }); const [, utils] = result.current; @@ -34,6 +34,21 @@ it('should get corresponding value for existing provided key', () => { expect(value).toBe(1); }); +it('should get corresponding value for existing provided key', () => { + const { result } = setUp({ foo: 'bar', a: 1 }); + + act(() => { + result.current[1].set('a', 99); + }); + + let value; + act(() => { + value = result.current[1].get('a'); + }); + + expect(value).toBe(99); +}); + it('should get undefined for non-existing provided key', () => { const { result } = setUp<{ foo: string; a: number; nonExisting?: any }>({ foo: 'bar', a: 1 }); const [, utils] = result.current; @@ -106,16 +121,3 @@ it('should reset map to initial object provided', () => { expect(result.current[0]).toEqual({ foo: 'bar', a: 1 }); }); - -it('should memoized its utils methods', () => { - const { result } = setUp({ foo: 'bar', a: 1 }); - const [, utils] = result.current; - const { set } = utils; - - act(() => { - set('foo', 'baz'); - }); - - expect(result.current[1]).toBe(utils); - expect(result.current[1].set).toBe(set); -});