mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 09:49:57 +08:00
d549964493
* demo: update demo * add * fix lint
45 lines
1.2 KiB
TypeScript
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;
|