Repository: streamich/react-use (ts)

Issue:
useMap(): outdated closure in `utils.get` method
**What is the current behavior?**

The value returned by the `get` is incorrect

https://github.com/streamich/react-use/blob/master/src/useMap.ts#L15
```
const utils = useMemo<Actions<T>>(
  () => ({
    // The reference to `map` is outdated
    get: key => map[key],
    // ...
  }),
  [set] // `map` is missing here in the dependency array.
);
```

Pull request:
fix: "get" method in useMap updated to reference latest map object
# Description

Fixes #816 

## Type of change

<!-- Check all relevant options. -->
- [x] Bug fix _(non-breaking change which fixes an issue)_
- [ ] New feature _(non-breaking change which adds functionality)_
- [ ] **Breaking change** _(fix or feature that would cause existing functionality to not work as before)_



Patch:
diff --git a/src/useMap.ts b/src/useMap.ts
index 85a83b5a..a0c60e96 100644
--- a/src/useMap.ts
+++ b/src/useMap.ts
@@ -27,7 +27,7 @@ const useMap = <T extends object = any>(initialMap: T = {} as T): [T, Actions<T>
       },
       reset: () => set(initialMap),
     }),
-    [set]
+    [map, set]
   );
 
   return [map, utils];


Test patch:
diff --git a/tests/useMap.test.ts b/tests/useMap.test.ts
index 1c238e12..58623f6b 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);
-});