Atlas is deprecated. Use AI Kit for any new Atlas experiences.
- Implementation
- InfiniteContent API
Common Examples
Basic Usage
Scrollable content with infinite loading:import { InfiniteContent } from "@servicetitan/anvil2-ext-atlas";
function InfiniteList() {
const [items, setItems] = useState([]);
const [hasMore, setHasMore] = useState(true);
const [loading, setLoading] = useState(false);
const loadMore = async () => {
setLoading(true);
const newItems = await fetchMoreItems();
setItems((prev) => [...prev, ...newItems]);
setHasMore(newItems.length > 0);
setLoading(false);
};
return (
<InfiniteContent
hasMore={hasMore}
loadingMore={loading}
onLoadMore={loadMore}
renderEndMessage={() => <div>No more items</div>}
>
{items.map((item) => (
<Item key={item.id} {...item} />
))}
</InfiniteContent>
);
}
With Scroll Callbacks
Track scroll position:import { InfiniteContent } from "@servicetitan/anvil2-ext-atlas";
function ScrollTrackingList() {
const [atTop, setAtTop] = useState(true);
return (
<InfiniteContent
hasMore={hasMore}
onLoadMore={loadMore}
onScrollDown={() => setAtTop(false)}
onScrollTop={() => setAtTop(true)}
>
{children}
</InfiniteContent>
);
}
Custom Loading Indicators
Customize loading and end messages:import { InfiniteContent, Loader } from "@servicetitan/anvil2-ext-atlas";
function CustomLoadingList() {
return (
<InfiniteContent
hasMore={hasMore}
loadingMore={isLoading}
onLoadMore={loadMore}
renderLoadingMore={() => <Loader />}
renderEndMessage={() => (
<div className="end-message">You've reached the end!</div>
)}
>
{children}
</InfiniteContent>
);
}
<InfiniteContent
loading={false}
hasMore={true}
loadingMore={false}
onLoadMore={handleLoadMore}
rootMargin="200px"
threshold={0.1}
renderLoadingMore={() => <Spinner />}
renderEndMessage={() => <div>End of list</div>}
onScrollDown={handleScrollDown}
onScrollTop={handleScrollTop}
>
{children}
</InfiniteContent>
InfiniteContent Props
ReactNode
The content to render inside the scrollable container.
string
Additional CSS class name for custom styling.
boolean
default:"false"
When true, enables infinite scroll loading.
boolean
default:"false"
When true and no children exist, shows the loading spinner.
boolean
default:"false"
When true, shows the loading more indicator.
() => void
Callback fired when more content should be loaded.
() => void
Callback fired when user scrolls past the threshold.
() => void
Callback fired when user scrolls back to top.
() => ReactNode
Custom render function for the end of list message.
() => ReactNode
Custom render function for the loading more indicator.
string
default:"200px"
Intersection Observer root margin for load trigger.
RefObject<HTMLElement>
Optional ref to custom scroll container element.
number
default:"50"
Pixel threshold for scroll callbacks.
number
default:"0.1"
Intersection Observer threshold for load trigger.