top | item 35064424

(no title)

cetra3 | 3 years ago

The example you highlighted as "doing it wrong" is pretty typical for an autosuggest component: Input updates trigger some request, which propagates to some list somewhere else in the dom. As it's loading, a spinner is shown, but when results are retrieved, they're updated again. Throw in apollo to the mix or some other request library, and context is used.

discuss

order

treis|3 years ago

Think you're gonna have a bad time. Should be something like:

function handleChange(e){

  getAutoSuggestions()

  setLoadingState(true)
}

^ Side effects happen in response to user input

function getAutoSuggestionsCallback(resp){

  setSuggestions(resp)

  setLoadingState(false)
}

^ No side effects