mirror of
https://github.com/bendtherules/some-hooks.git
synced 2026-08-19 00:34:17 +00:00
useBoolean, useStateWithReset - Add hooks
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { useState, useCallback } from "react";
|
||||
|
||||
const useStateWithReset = <TValue>(initial: TValue) => {
|
||||
const [value, setValue] = useState<TValue>(initial);
|
||||
return {
|
||||
value,
|
||||
setValue,
|
||||
reset: useCallback(() => setValue(initial), [])
|
||||
};
|
||||
};
|
||||
|
||||
export default useStateWithReset;
|
||||
Reference in New Issue
Block a user