demo: demo code optimization (#47680)

This commit is contained in:
lijianan 2024-03-02 10:47:22 +08:00 committed by GitHub
parent 7abae5e973
commit 6f68cf30ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,22 +1,20 @@
import React, { useState } from 'react';
import React from 'react';
import { AutoComplete } from 'antd';
import type { DefaultOptionType } from 'antd/es/select';
const App: React.FC = () => {
const [options, setOptions] = useState<{ value: string; label: string }[]>([]);
const [options, setOptions] = React.useState<DefaultOptionType[]>([]);
const handleSearch = (value: string) => {
let res: { value: string; label: string }[] = [];
if (!value || value.indexOf('@') >= 0) {
res = [];
} else {
res = ['gmail.com', '163.com', 'qq.com'].map((domain) => ({
value: `${value}@${domain}`,
setOptions(() => {
if (!value || value.includes('@')) {
return [];
}
return ['gmail.com', '163.com', 'qq.com'].map<DefaultOptionType>((domain) => ({
label: `${value}@${domain}`,
value: `${value}@${domain}`,
}));
}
setOptions(res);
});
};
return (
<AutoComplete
style={{ width: 200 }}