Examples & API Integration

Comprehensive examples showing how to integrate mantine-select-async-paginate with real paginated APIs. Learn best practices for handling async data, pagination, and user interactions.

Key Features Demonstrated

Single & Multi-select
Real API Integration
Infinite Scroll
Advanced Customization

Basic Examples

Start with these fundamental examples to understand how AsyncPaginateSelect works with mock data.

Single Select

Basic single-select with pagination, search, and caching.

Type to search or scroll to load more options

import { AsyncPaginateSelect } from 'mantine-select-async-paginate';

const loadOptions = async (search, loadedOptions, additional) => {
  const response = await fetch(`/api/options?search=${search}&page=${additional?.page || 0}`);
  const data = await response.json();
  
  return {
    options: data.items.map(item => ({
      value: item.id,
      label: item.name
    })),
    hasMore: data.hasMore,
    additional: { page: (additional?.page || 0) + 1 }
  };
};

<AsyncPaginateSelect
  value={value}
  onChange={setValue}
  loadOptions={loadOptions}
  defaultOptions
  cacheOptions
  clearable
/>

Multi-Select (Dedicated Component)

Use AsyncPaginateMultiSelect for dedicated multi-selection functionality.

Select up to 5 options. Only first 3 shown, rest as +N more

import { AsyncPaginateMultiSelect } from 'mantine-select-async-paginate';

<AsyncPaginateMultiSelect
  value={selectedValues}
  onChange={setSelectedValues}
  loadOptions={loadOptions}
  maxSelectedValues={5}
  excludeSelected={true}
  maxDisplayedValues={3}
  defaultOptions
  cacheOptions
/>

Multi-Select (Single Component)

Use the multiple prop on AsyncPaginateSelect for multi-selection mode.

Using multiple prop. Shows 2 items max, rest as +N more

import { AsyncPaginateSelect } from 'mantine-select-async-paginate';

<AsyncPaginateSelect
  multiple={true}
  value={selectedValues}
  onChange={setSelectedValues}
  loadOptions={loadOptions}
  maxSelectedValues={4}
  excludeSelected={true}
/>

Key Features Demonstrated

Pagination: Automatically loads more data when scrolling to bottom

Search: Debounced search with 300ms delay

Caching: Results are cached to avoid unnecessary API calls

Loading States: Built-in loading indicators

Error Handling: Graceful error handling with user feedback

TypeScript: Full TypeScript support with proper typing

Customization: Extensive prop support for customization

Quick API Reference

APIs used in these examples - all free and no authentication required:

DummyJSON

Users, products, posts with built-in pagination

https://dummyjson.com/

ReqRes.in

User management with page-based pagination

https://reqres.in/api/

GitHub API

Repositories, users with Link header pagination

https://api.github.com/

JSONPlaceholder

Posts, users, todos with offset/limit pagination

https://jsonplaceholder.typicode.com/