如何解决通过单击按钮传递文本字段值
这是包含文本字段和按钮的代码。我想用文本字段的值调用“apiFetcher”函数。我在文本字段中注释掉了 onblur 功能。那工作得很好。任何解决此问题的建议。
<Autocomplete
id="free-solo-2-demo"
disableClearable
options={Cities.map((option) => option.name)}
renderInput={(params) => (
<div
>
<TextField
id="standard-basic"
{...params}
label="city"
margin="normal"
InputProps={{ ...params.InputProps,type: 'search' }}
// onBlur={apiFtecher}
/>
</div>
)}
/>
</Grid>
<Grid className={classes.seIcon} item xs={1}>
<div onClick={apiFtecher}>
<IconButton>
<SearchIcon/>
</IconButton>
</div>
</Grid>
这里是apiFetcher函数
const apiFtecher = e => {
setcity(e.target.value);
console.log(city);
}
解决方法
这是我做的
const [town,settown]=useState("");
function APIsetter(){
return(
setcity(town)
)
}
然后将 APIsetter 绑定到按钮的 onclick 函数上,就成功了
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。