diff options
| author | Haishan <[email protected]> | 2020-10-31 18:18:04 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2020-11-01 17:42:52 +0800 |
| commit | ff1a39d04e53b428e34d46c55ecd6689189b5443 (patch) | |
| tree | 94a60abe3d28a1d729b877356bdd38d75ce655a5 /src/hooks/basic.ts | |
| parent | e62c9165481ef12ee2310dee1c32f890b3fe4b78 (diff) | |
chore: run ts-migrate
Diffstat (limited to 'src/hooks/basic.ts')
| -rw-r--r-- | src/hooks/basic.ts | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/hooks/basic.ts b/src/hooks/basic.ts new file mode 100644 index 0000000..c8eddbc --- /dev/null +++ b/src/hooks/basic.ts @@ -0,0 +1,9 @@ +import React from 'react'; + +const { useState, useCallback } = React; + +export function useToggle(initialValue = false) { + const [isOn, setState] = useState(initialValue); + const toggle = useCallback(() => setState(x => !x), []); + return [isOn, toggle]; +} |
