Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript react select-buffer onChange事件_Javascript_Reactjs - Fatal编程技术网

Javascript react select-buffer onChange事件

Javascript react select-buffer onChange事件,javascript,reactjs,Javascript,Reactjs,我需要暂停react select组件的onChange,直到数据加载到options中。怎么可能呢 const handleSearch = () => { // call data to redux and add to function getOptions (THIS WORK OK - this doesn't interest me) } const handleSelect = () => { // need pause event while handleSea

我需要暂停react select组件的onChange,直到数据加载到options中。怎么可能呢

const handleSearch = () => {
 // call data to redux and add to function getOptions (THIS WORK OK - this doesn't interest me)
}

const handleSelect = () => {
 // need pause event while handleSearch is completed
 // **how to do this**
}

<Select
  ...
  isLoading={isSearching} 
  onInputchange={handleSearch}
  onChange={handleSelect}
  options={getOptions}
  ...
/>
consthandlesearch=()=>{
//将数据调用到redux并添加到函数getOptions(这项工作正常-我对此不感兴趣)
}
const handleSelect=()=>{
//handleSearch完成时需要暂停事件
//**如何做到这一点**
}

创建新状态以检测句柄搜索是否完成

const [isHandleSearchComplete, markHandleSearchAsComplete] = useState(false);

const handleSearch = () => {
    getOptions().then((res) => {
        // do something here
        markHandleSearchAsComplete(true)
    })
}

const handleSelect = () => {
    // if handle search is complete then stop the process
    if (isHandleSearchComplete) {
        return
    }

    // otherwise, do something
}

一个选项是可以禁用选择框,直到数据可用。将
isDisabled
设置为true,直到数据可用。我需要捕获enter事件,只有在读取数据后才会确认enter(不再按enter)。您可以在等待数据时键入搜索框此函数起作用,我需要处理函数
handleSelect
@user3061527我被您的问题弄糊涂了。我已更新我的回答我不想停止
handleSelect
,而是暂停,因此暂停执行
handleSelect
,直到加载数据,然后自动执行
handleSelect