'React-Select (LIVE DATA)

So I understand that I can use the below code to search for Async data however I can't work out how to make it query a URL that has the data instead of relying on a custom data file that has the data already inside it.

We have over 6000 suburbs and to preload that type of data would take our system quite sometime, so to be able to search for it as the user types make more sense.

import React, { Component } from 'react';

import AsyncSelect from 'react-select/async';
import { ColourOption, colourOptions } from '../data';

const filterColors = (inputValue: string) => {
  return colourOptions.filter((i) =>
    i.label.toLowerCase().includes(inputValue.toLowerCase())
  );
};

const promiseOptions = (inputValue: string) =>
  new Promise<ColourOption[]>((resolve) => {
    setTimeout(() => {
      resolve(filterColors(inputValue));
    }, 1000);
  });

export default class WithPromises extends Component {
  render() {
    return (
      <AsyncSelect cacheOptions defaultOptions loadOptions={promiseOptions} />
    );
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source