[英]Re-render select option after user has selected an option and pressed submit in ReactJS
I am new to React.我是 React 的新手。 I am trying to understand how to use hooks and states but I am having some trouble.
我试图了解如何使用钩子和状态,但我遇到了一些麻烦。 I am displaying some options in the select tag and after the user selects one option and clicks on submit I want to remove that option from the list of options without having the user to refresh.
我在 select 标记中显示一些选项,在用户选择一个选项并单击提交后,我想从选项列表中删除该选项,而无需用户刷新。
<form onSubmit={handleSubmit} className="row valign-wrapper">
<div className="input-field col s12 l6">
<select className="browser-default" onChange={(e) => setSelected(e.target.value)} value={selected}>
<option value="None">Select</option>
{ institutions.map(institution => (
<option key={institution._id} value={institution._id}>{institution.name}</option>
))}
</select>
</div>
<div className="col s12 l6">
<button className="btn waves-effect waves-light indigo" type="submit">Apply</button>
</div>
</form>
Just add this to your form onSubmit={(e)=>e.preventDefault()}只需将其添加到您的表单 onSubmit={(e)=>e.preventDefault()}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.