如果您使用的是React Hooks,请使用以下命令:
import React, { useState } from 'react'import { Button, Select } from 'antd'const { Option } = Select// inside your componentconst ComponentName = () => { const [selected, setSelected] = useState() // handler const clearSelected = () => { // this line will clear the select // when you click on the button setSelected(null) } // in the return value return ( <> // ... // In the select element <Select style={{ width: 150 }} onChange={value => setSelected(value)} value={selected}> <Option value="jack">Jack</Option> <Option value="lucy">Lucy</Option> </Select> <Button onClick={clearSelected}>Clear Selected</Button> </> )}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)