How the StateChanger works
mainThe stateChanger object is passed to your onInfinite function. You must call one of its methods to inform the component of the loading result:
stateChanger.loaded(): Marks a successful load and continues listening for the next trigger.stateChanger.complete(): Ends the infinite loading process. It will display thenoResultssnippet if no items were ever loaded, or thenoMoresnippet if items were previously loaded.stateChanger.error(): Signals a failure and displays theerrorsnippet.stateChanger.reset(): Resets the component state (functionally equivalent to changing theidentifierprop).
// Example of using stateChanger methods
async function loadMore(stateChanger: StateChanger) {
const data = await fetchData();
if (data.length === 0) {
stateChanger.complete(); // Shows 'noMore' or 'noResults'
} else {
stateChanger.loaded(); // Continues scrolling
}
}