React-tags: 服务器端自动完成示例?

创建于 2020-04-30  ·  4评论  ·  资料来源: i-like-robots/react-tags

question

最有用的评论

幸运的是,我几天前做了这个😄: https :

所有4条评论

幸运的是,我几天前做了这个😄: 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处理程序中查询服务器时,需要一些时间。
因此,选项列表始终包含上次调用的建议列表,而不是最新调用的建议列表。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

filippofilip95 picture filippofilip95  ·  4评论

ekinalcar picture ekinalcar  ·  10评论

famouspotatoes picture famouspotatoes  ·  5评论

williamsidewalk picture williamsidewalk  ·  4评论

thienanle picture thienanle  ·  9评论