demo: improve Select demo (#41986)

Co-authored-by: songzihao <zihao.szh@digital-engine.com>
This commit is contained in:
sexnmaa 2023-04-25 22:34:23 +08:00 committed by GitHub
parent 4d0f399f0b
commit ab5ebb0278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,8 +32,11 @@ const fetch = (value: string, callback: Function) => {
}
});
};
timeout = setTimeout(fake, 300);
if (value) {
timeout = setTimeout(fake, 300);
} else {
callback([]);
}
};
const SearchInput: React.FC<{ placeholder: string; style: React.CSSProperties }> = (props) => {
@ -41,11 +44,7 @@ const SearchInput: React.FC<{ placeholder: string; style: React.CSSProperties }>
const [value, setValue] = useState<string>();
const handleSearch = (newValue: string) => {
if (newValue) {
fetch(newValue, setData);
} else {
setData([]);
}
fetch(newValue, setData);
};
const handleChange = (newValue: string) => {