Javascript react select-buffer onChange事件
我需要暂停react select组件的onChange,直到数据加载到options中。怎么可能呢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
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