import React, { useState } from 'react'; import jsonp from 'fetch-jsonp'; import qs from 'qs'; import { Select } from 'antd'; import type { SelectProps } from 'antd'; let timeout: ReturnType | null; let currentValue: string; const fetch = (value: string, callback: Function) => { if (timeout) { clearTimeout(timeout); timeout = null; } currentValue = value; const fake = () => { const str = qs.stringify({ code: 'utf-8', q: value, }); jsonp(`https://suggest.taobao.com/sug?${str}`) .then((response: any) => response.json()) .then((d: any) => { if (currentValue === value) { const { result } = d; const data = result.map((item: any) => ({ value: item[0], text: item[0], })); callback(data); } }); }; if (value) { timeout = setTimeout(fake, 300); } else { callback([]); } }; const SearchInput: React.FC<{ placeholder: string; style: React.CSSProperties }> = (props) => { const [data, setData] = useState([]); const [value, setValue] = useState(); const handleSearch = (newValue: string) => { fetch(newValue, setData); }; const handleChange = (newValue: string) => { setValue(newValue); }; return (