React-tags: Beispiel für serverseitige Autovervollständigung?

Erstellt am 30. Apr. 2020  ·  4Kommentare  ·  Quelle: i-like-robots/react-tags

question

Hilfreichster Kommentar

Zum Glück habe ich das vor ein paar Tagen gemacht 😄: https://github.com/i-like-robots/react-tags/compare/v5.13.0...async-fetch-example

Alle 4 Kommentare

Zum Glück habe ich das vor ein paar Tagen gemacht 😄: https://github.com/i-like-robots/react-tags/compare/v5.13.0...async-fetch-example

yay!, suche gerade danach!

Beispiel mit Axios und Hooks:

  //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])

Der Rest des Codes bleibt der gleiche wie der @i-like-robots PR

Danke für das Beispiel, es scheint ein kleines Problem @i-like-robots zu geben.
Die Optionsliste wird direkt nach dem benutzerdefinierten onInput Handler https://github.com/i-like-robots/react-tags/blob/6.0/lib/ReactTags.js#L130 aktualisiert
Wenn ich jedoch den Server innerhalb des onInput Handlers abfrage, dauert es einige Zeit.
Als Ergebnis enthält die Optionsliste immer eine Liste mit Vorschlägen aus dem vorherigen Anruf, nicht aus dem neuesten.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

filippofilip95 picture filippofilip95  ·  4Kommentare

ekinalcar picture ekinalcar  ·  10Kommentare

yrik picture yrik  ·  10Kommentare

thienanle picture thienanle  ·  9Kommentare

famouspotatoes picture famouspotatoes  ·  5Kommentare