幸运的是,我几天前做了这个😄: https :
耶!,只是在找这个!
使用 axios 和钩子的示例:
//initial api call
const [{ data: labelsData }, doGetLabels] = useAxios({
url: '/labels',
})
const [suggestions, setSuggestions] = useState([])
const [busy, setBusy] = useState(false)
const handleInputChange = debounce((name) => {
if (!busy) {
setBusy(true)
doGetLabels({ params: { name } })
}
})
//getResponseData is my custom parser for the BE response
useEffect(() => {
const labels = labelsData ? getResponseData(labelsData).labels : []
if (setBusy) {
setBusy(false)
}
setSuggestions(labels)
}, [labelsData])
其余代码与@i-like-robots PR 相同
感谢您的示例,@i-like-robots 似乎有一个小问题。
选项列表在onInput
自定义处理程序https://github.com/i-like-robots/react-tags/blob/6.0/lib/ReactTags.js#L130之后直接更新
但是,当我在onInput
处理程序中查询服务器时,需要一些时间。
因此,选项列表始终包含上次调用的建议列表,而不是最新调用的建议列表。
最有用的评论
幸运的是,我几天前做了这个😄: https :