mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-31 05:08:03 +08:00
14a1e6bd51
* feat: tsconfig enable strict * feat: add no-explicit-any * feat: strict * feat: as THEME * feat: 优化 keys 类型写法 * feat: demo remove any * feat: as number * feat: this any * feat: add eslint * feat: cascader * feat: props any * feat: remove any * feat: remove any * feat: any 提示错误 * feat: remove any * feat: add eslint * feat: 允许 T = any 存在 * feat: color funciton * feat: 恢复 lint * feat: merge master * feat: as ReactElement * feat: type
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { Select, Space } from 'antd';
|
|
|
|
const cityData = {
|
|
Zhejiang: ['Hangzhou', 'Ningbo', 'Wenzhou'],
|
|
Jiangsu: ['Nanjing', 'Suzhou', 'Zhenjiang'],
|
|
};
|
|
|
|
type CityName = keyof typeof cityData;
|
|
|
|
const provinceData: CityName[] = ['Zhejiang', 'Jiangsu'];
|
|
|
|
const App: React.FC = () => {
|
|
const [cities, setCities] = useState(cityData[provinceData[0] as CityName]);
|
|
const [secondCity, setSecondCity] = useState(cityData[provinceData[0]][0] as CityName);
|
|
|
|
const handleProvinceChange = (value: CityName) => {
|
|
setCities(cityData[value]);
|
|
setSecondCity(cityData[value][0] as CityName);
|
|
};
|
|
|
|
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;
|