Skip to content

Commit

Permalink
demo: demo code optimization (ant-design#47680)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan authored and tanzhenyun committed Mar 29, 2024
1 parent 39f24c5 commit 456cff8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions components/auto-complete/demo/options.tsx
Original file line number Diff line number Diff line change
@@ -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 }}
Expand Down

0 comments on commit 456cff8

Please sign in to comment.