reactjs - 语义用户界面反应:Form.Select 中的大型数据集是否会使表单变慢?
问题描述
我正在使用语义-ui-react 创建以下表单(内部模态)。
<Modal open={editBasicModal} size="small">
<Modal.Header>Your basic details</Modal.Header>
<Modal.Content scrolling>
<Form loading={isSubmitting}>
<Form.Group inline widths="equal">
<Form.Input
required
label="First Name"
fluid
type="text"
name="firstName"
value={values.firstName}
onChange={handleChange}
error={errors.firstName !== undefined}
/>
<Form.Input
required
label="Last Name"
fluid
type="text"
name="lastName"
value={values.lastName}
onChange={handleChange}
error={errors.lastName !== undefined}
/>
</Form.Group>
<Form.TextArea
label="Bio"
type="text"
name="bio"
value={values.bio}
onChange={handleChange}
rows={3}
error={errors.bio !== undefined}
/>
<Form.Select
label="Country"
name="location.country"
placeholder="Country"
value={values.location.country}
onChange={(e, { value }) => {
setFieldValue("location.country", value);
}}
options={this.state.allCountries}
/>
</Form>
</Modal.Content>
<Modal.Actions open={true}>
<Button type="submit" onClick={handleSubmit} >
Update
</Button>
</Modal.Actions>
</Modal>
上面的代码来自一个使用 Formik + yup 的组件。
this.state.allCountries
是一个包含 200 多条记录的数组。现在这让我的表格变慢了,里面的打字textarea
也input
很慢。
根据我的发现, 中的大型数据集Form.Select
导致了问题,因为如果我替换options={this.state.allCountries}
to options={[ { key: 1, value: "india", text: "india"} ]}
,一切都开始正常工作。或者,如果我删除Form.Select
then 表格也可以正常工作。
几个问题?
- 这是一个已知问题吗?
- 有哪些可能的解决方案?
解决方案
我发现这是Form.Select
. 我改变了它,select
然后一切都很顺利。这是选择的更新代码:
<Form.Field >
<label htmlFor="location.country">Country</label>
<select
name="location.country"
id="location.country"
value={values.location.country }
onChange={event => {
setFieldValue("location.country", event.target.value);
}}
>
<option key={0} value={undefined}>
-select-
</option>
{this.state.allCountries}
</select>
</Form.Field>
这呈现类似(有点)选择元素,没有缓慢问题。
希望它会帮助某人。
推荐阅读
- dart - 基于约束分配对象的简单方法?
- python - 双向 LSTM 结构,数据形状不正确
- javascript - 如何使 div 成为能够选择文本的自定义鼠标光标?
- java - Intellij Debug Docker 容器不断给我 IO Exception Handshake Failed
- python - 解决 Tensorflow 中的约束优化
- android - Recyclerview 中不显示改造响应对象
- javascript - Chrome 扩展强制左键单击
- javascript - 使用 Jquery 和 Fetch 将多个文件发送到 PHP
- discord.js - discord.js API 中如何使用不同语言实现服务器?
- ubuntu - vagrant 给出:错误:'~ansible' 用户或团队不存在