diff options
| author | Matain <[email protected]> | 2022-06-12 23:34:56 +0800 |
|---|---|---|
| committer | Matain <[email protected]> | 2022-06-12 23:34:56 +0800 |
| commit | ea5d7cf003eeef30cb7bbe789c6ba7f314bf1ce4 (patch) | |
| tree | bff1bd7b0e8e8eb753d373b57f007bbe97f96c76 /src/hooks | |
| parent | 4fd2c8f646e48dd0c07d0c2041de52e9a4f8bc82 (diff) | |
| parent | 38571da24ac54137564be5e41b7a409009e2ee10 (diff) | |
Merge branch 'master' of https://github.com/haishanh/yacd into haishanh-master
Diffstat (limited to 'src/hooks')
| -rw-r--r-- | src/hooks/basic.ts | 9 | ||||
| -rw-r--r-- | src/hooks/useRemainingViewPortHeight.ts | 7 | ||||
| -rw-r--r-- | src/hooks/useTextInput.ts | 4 |
3 files changed, 12 insertions, 8 deletions
diff --git a/src/hooks/basic.ts b/src/hooks/basic.ts index 587d92d..1e8aeae 100644 --- a/src/hooks/basic.ts +++ b/src/hooks/basic.ts @@ -1,9 +1,14 @@ -import React from 'react'; +import * as React from 'react'; const { useState, useCallback } = React; -export function useToggle(initialValue = false) { +export function useToggle(initialValue = false): [boolean, () => void] { const [isOn, setState] = useState(initialValue); const toggle = useCallback(() => setState((x) => !x), []); return [isOn, toggle]; } + +export function useState2<T>(v: T) { + const [value, set] = useState(v); + return { value, set }; +} diff --git a/src/hooks/useRemainingViewPortHeight.ts b/src/hooks/useRemainingViewPortHeight.ts index 9f3470d..2c920c2 100644 --- a/src/hooks/useRemainingViewPortHeight.ts +++ b/src/hooks/useRemainingViewPortHeight.ts @@ -9,9 +9,10 @@ const { useState, useRef, useCallback, useLayoutEffect } = React; * to the bottom of the view port * */ -export default function useRemainingViewPortHeight< - ElementType extends HTMLDivElement ->(): [React.MutableRefObject<ElementType>, number] { +export default function useRemainingViewPortHeight<ElementType extends HTMLDivElement>(): [ + React.MutableRefObject<ElementType>, + number +] { const ref = useRef<ElementType>(null); const [containerHeight, setContainerHeight] = useState(200); const updateContainerHeight = useCallback(() => { diff --git a/src/hooks/useTextInput.ts b/src/hooks/useTextInput.ts index 1fa19f7..853044c 100644 --- a/src/hooks/useTextInput.ts +++ b/src/hooks/useTextInput.ts @@ -9,9 +9,7 @@ export function useTextInut( ): [(e: React.ChangeEvent<HTMLInputElement>) => void, string] { const [, setTextGlobal] = useRecoilState(x); const [text, setText] = useState(''); - const setTextDebounced = useMemo(() => debounce(setTextGlobal, 300), [ - setTextGlobal, - ]); + const setTextDebounced = useMemo(() => debounce(setTextGlobal, 300), [setTextGlobal]); const onChange = useCallback( (e: React.ChangeEvent<HTMLInputElement>) => { setText(e.target.value); |
