简体   繁体   English

使用带有 antd select 的去抖动搜索处理程序

[英]Using a debounced search handler with antd select

I am trying to create a wrapper component around antd's Select, that adds a debounced function to handle search input.我正在尝试围绕 antd 的 Select 创建一个包装器组件,它添加了一个去抖动的 function 来处理搜索输入。 I am using lodash's debounce util function.我正在使用 lodash 的 debounce util function。

However I run into a bug where:但是我遇到了一个错误:

  • you type and pause to let the debounced function fire, the first time, this works fine.您键入并暂停以让去抖动的 function 触发,这是第一次,效果很好。
  • However when you then try adding keypresses to the search Text, the searchValue is not generated as expected.但是,当您随后尝试将按键添加到搜索文本时,不会按预期生成 searchValue。

I have created a minimal sandbox that replicates this behavior here: https://codesandbox.io/s/vigorous-glade-495f2z?file=/src/Select.jsx .我在这里创建了一个复制此行为的最小沙箱: https://codesandbox.io/s/vigorous-glade-495f2z?file=/src/Select.jsx

Remove the searchValue props from the Select component.Select组件中删除searchValue属性。

const propsToSelect = {
    ...props,
    style: { width: "300px" },
    onSearch: searchHandlerWithDebounce,
    filterOption: false,
    options: []
  };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM