feat: useMap: allow resetting with provided value other then initial

This commit is contained in:
Mateusz Leonowicz 2020-01-17 15:03:35 +00:00
parent fc595e8618
commit 7645f7249d
2 changed files with 5 additions and 2 deletions

View File

@ -18,7 +18,10 @@ const Demo = () => {
Add
</button>
<button onClick={() => reset()}>
Reset
Reset to initial
</button>
<button onClick={() => reset({hello: 'different'})}>
Reset with new object
</button>
<button onClick={() => remove('hello')} disabled={!map.hello}>
Remove 'hello'

View File

@ -27,7 +27,7 @@ const useMap = <T extends object = any>(initialMap: T = {} as T): [T, Actions<T>
return rest as T;
});
},
reset: () => set(initialMap),
reset: (newMap = initialMap) => set(newMap),
}),
[set]
);