diff options
| author | Haishan <[email protected]> | 2020-06-22 22:35:59 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2020-06-22 22:35:59 +0800 |
| commit | b93c0267c88d8d64297fa6cc88ef5e3657c6cc7a (patch) | |
| tree | 06ed9d5e4463c909ed99b87232c592ffbf9a2792 /src | |
| parent | 31fbdfc3df61441f7caf507c83a8e38c503bd7ef (diff) | |
fix: fix can not type in Chinese in proxy text filter input
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/proxies/TextFilter.tsx | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/components/proxies/TextFilter.tsx b/src/components/proxies/TextFilter.tsx index acf83ae..6465572 100644 --- a/src/components/proxies/TextFilter.tsx +++ b/src/components/proxies/TextFilter.tsx @@ -1,24 +1,31 @@ +import debounce from 'lodash-es/debounce'; import * as React from 'react'; import { useRecoilState } from 'recoil'; import { proxyFilterText } from '../../store/proxies'; import shared from '../shared.module.css'; -const { useCallback } = React; +const { useCallback, useState, useMemo } = React; export function TextFilter() { - const [text, setText] = useRecoilState(proxyFilterText); + const [, setTextGlobal] = useRecoilState(proxyFilterText); + const [text, setText] = useState(''); + + const setTextDebounced = useMemo(() => debounce(setTextGlobal, 300), [ + setTextGlobal, + ]); + const onChange = useCallback( (e: React.ChangeEvent<HTMLInputElement>) => { setText(e.target.value); + setTextDebounced(e.target.value); }, - [setText] + [setTextDebounced] ); return ( <input className={shared.input} - spellCheck={false} type="text" value={text} onChange={onChange} |
