Try to combine with react-infinite-scroll-hook
Something like this:
const [sentryRef, { rootRef }] = useInfiniteScroll({
loading: isLoading,
hasNextPage,
disabled: !open,
onLoadMore: () => debouncedOptionsLoad(),
});
...
const renderSentry = () => {
return hasNextPage || isLoading ? (
<ListItem ref={sentryRef} key="sentry">
Loading...
</ListItem>
) : null;
};
...
const handleRenderOption = (optionProps, option) => {
const { id, label } = option;
if (id === "sentry") {
return renderSentry();
}
return (
<ListItem {...optionProps} key={id}>
//for highlighting input string
<Hightlight value={label} filter={searchString} />
</ListItem>
);
};
...
const sentryOption = { id: "sentry", label: '' };
...
return (
<MuiAutocomplete
...some props
//rootRef from useInfiniteScroll hook
ListboxProps={{ ref: rootRef }},
filterOptions={(filterOptions) => {
//filterOptions need for adding sentry to your options
const shouldRenderSentry = meta.hasNextPage;
if (shouldRenderSentry) {
filterOptions.push(sentryOption);
}
return filterOptions;
}},
renderInput={(inputProps) => (
<TextField
value={searchString}
onChange={ //function for change "searchString" and refetch your data }
/>
)}
...
/>