【发布时间】:2021-12-29 03:44:24
【问题描述】:
大家好,我有一个关于单击图标后如何清除 TextField 的问题?谢谢
const [filteredLocations, setFilteredLocations] = useState(locations);
const clearSearch = () => {
// i dont know what should i put here TextField.clear() or so what ever
};
const filterResults = (e) => {
....
setFilteredLocations(filteredLocations);
};
<TextField
placeholder="Search Locations"
onChange={filterResults}
InputProps={{
endAdornment: (
<IconButton onClick={clearSearch} edge="end">
<ClearIcon />
</IconButton>
)
}}
/>
【问题讨论】:
-
您的
TextField不受控制,因此无法更改其值。见uncontrolled vs controlled
标签: javascript reactjs material-ui