Skip to content

Commit

Permalink
feat: useMap: allow resetting with provided value other then initial
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleonowicz committed Jan 17, 2020
1 parent fc595e8 commit 7645f72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/useMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/useMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
Expand Down

0 comments on commit 7645f72

Please sign in to comment.