React Select's AsyncSelect loads dropdown options from an API as the user types. You pass it a loadOptions function that returns a promise (or calls a callback), and the component handles the loading state, empty state and rendering. Import it from react-select/async.
The old tutorial pattern of importing react-select/dist/react-select.css only applies to react-select v1. Current versions (v5) style themselves with Emotion, so no CSS import is needed.
Install the library in any React 17, 18 or 19 project (Vite, Next.js or similar). You do not need Axios; the built-in fetch API is enough.
For TypeScript, react-select v5 ships its own types, so no @types package is required.
AsyncSelect calls loadOptions(inputValue) each time the input changes. It can be written in two styles:
| Style | Signature | Notes |
|---|---|---|
| Promise | (input) => Promise<Option[]> | Preferred; works with async/await. |
| Callback | (input, callback) => void | Older style; call callback(options) when done. |
Each option is an object with a label (shown to the user) and a value (the identifier). You can add extra fields and read them back from onChange.
This example searches a remote endpoint and keeps the selected option in state. It uses fetch with AbortController so a slow, outdated response never overwrites a newer one.
The /api/search endpoint is a placeholder: replace it with your own route and adapt the mapping to your response shape.
loadOptions runs on every keystroke, so a fast typist can fire many requests. Debounce it so only the last input is sent. A small helper that returns a promise works well:
Pass debouncedLoadOptions to loadOptions. If you already use a library such as lodash, its debounce works with the callback style.
defaultOptions: set to true to call loadOptions("") on mount, or pass an array of initial options.cacheOptions: caches results per input value so repeated searches do not refetch.isMulti: allow several selected options; onChange then receives an array.isLoading, loadingMessage: customise the loading indicator text.inputId: lets a <label htmlFor> point at the input for accessibility.Pass defaultOptions and cacheOptions together when the list is small and the same queries repeat.
In v5 you style parts of the component through the styles prop, classNames or classNamePrefix, not a stylesheet import:
Give the input a visible label and an inputId, and keep the default keyboard behaviour: react-select already supports arrow keys, Enter and Escape and exposes ARIA attributes.
That file existed only in react-select v1. Version 2 and later use CSS-in-JS, so remove the import and style through props.
Either works. fetch removes a dependency and supports cancellation through AbortController. Axios also supports cancellation and is fine if you already use it.
Set defaultOptions to true to load the initial list with an empty query, or pass a fixed array of options.
Use the name prop to render a hidden input with the selected value, or read the value from onChange and submit it yourself.
Use AsyncSelect from react-select/async with a promise-returning loadOptions, map your API rows to { label, value }, and keep the selection in state. Cancel stale requests, debounce typing, drop the obsolete CSS import and style through the v5 props.