reactjs - semantic-ui-react:Form.Select 中的大型数据集是否会使表单变慢?

标签 reactjs html semantic-ui-react

我正在使用 semantic-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 多条记录的数组。现在这让我的表单变慢了,textareainput 中的输入非常慢。

根据我的发现,Form.Select 中的大型数据集导致了这个问题,因为如果我将 options={this.state.allCountries} 替换为 options={[ { key: 1, value: "india", text: "india"} ]},一切开始正常工作。或者,如果我删除 Form.Select,则表单也可以正常工作。

几个问题?

  1. 这是一个已知问题吗?
  2. 有哪些可能的解决方案?

最佳答案

我发现这是 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>

这呈现了类似(有点)的选择元素,没有缓慢问题。

希望对大家有帮助。

关于reactjs - semantic-ui-react:Form.Select 中的大型数据集是否会使表单变慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55971850/

相关文章:

javascript - css bootstrap select 将显示刻度标记移动到下拉菜单中文本的左侧

reactjs - 通过单击在另一个组件中呈现的元素来打开 <Modal>

reactjs - 在 Semantic-UI-React 中导入 CSS

reactjs - Firebase 库无法在 Next.js 中使用 '@grpc/grpc-js'

reactjs - Redux-saga:dispatch 有时不会触发 saga

javascript - 在 React 中从子级更新状态

html - <body> 内容不粘在浏览器的右边缘

javascript - Google Places API 地点类型问题

reactjs - 从 SemanticUI 中的 onClick 操作中检索输入值

reactjs - Redux-thunk 调度不是函数错误