ant-design/components/select/demo/coordinate.tsx
lijianan d549964493
demo: update demo (#40313)
* demo: update demo

* add

* fix lint
2023-01-18 19:20:40 +08:00

45 lines
1.2 KiB
TypeScript

import React, { useState } from 'react';
import { Select, Space } from 'antd';
const provinceData = ['Zhejiang', 'Jiangsu'];
const cityData = {
Zhejiang: ['Hangzhou', 'Ningbo', 'Wenzhou'],
Jiangsu: ['Nanjing', 'Suzhou', 'Zhenjiang'],
};
type CityName = keyof typeof cityData;
const App: React.FC = () => {
const [cities, setCities] = useState(cityData[provinceData[0] as CityName]);
const [secondCity, setSecondCity] = useState(cityData[provinceData[0] as CityName][0]);
const handleProvinceChange = (value: CityName) => {
setCities(cityData[value]);
setSecondCity(cityData[value][0]);
};
const onSecondCityChange = (value: CityName) => {
setSecondCity(value);
};
return (
<Space wrap>
<Select
defaultValue={provinceData[0]}
style={{ width: 120 }}
onChange={handleProvinceChange}
options={provinceData.map((province) => ({ label: province, value: province }))}
/>
<Select
style={{ width: 120 }}
value={secondCity}
onChange={onSecondCityChange}
options={cities.map((city) => ({ label: city, value: city }))}
/>
</Space>
);
};
export default App;