function useInfiniteLoader(loadMoreItems, options = emptyObj) {
  const {
    isItemLoaded,
    minimumBatchSize = 16,
    threshold = 16,
    totalItems = 9e9,
  } = options
  const storedLoadMoreItems = (0, _latest.default)(loadMoreItems)
  const storedIsItemLoaded = (0, _latest.default)(isItemLoaded)
  return React.useCallback(
    (startIndex, stopIndex, items) => {
      const unloadedRanges = scanForUnloadedRanges(
        storedIsItemLoaded.current,
        minimumBatchSize,
        items,
        totalItems,
        Math.max(0, startIndex - threshold),
        Math.min(totalItems - 1, (stopIndex || 0) + threshold)
      ) // The user is responsible for memoizing their loadMoreItems() function
      // because we don't want to make assumptions about how they want to deal
      // with `items`

      for (let i = 0; i < unloadedRanges.length - 1; ++i)
        storedLoadMoreItems.current(
          unloadedRanges[i],
          unloadedRanges[++i],
          items
        )
    },
    [
      totalItems,
      minimumBatchSize,
      threshold,
      storedLoadMoreItems,
      storedIsItemLoaded,
    ]
  )
}
/**
 * A utility hook for seamlessly adding infinite scroll behavior to the `useMasonry()` hook. This
 * hook invokes a callback each time the last rendered index surpasses the total number of items
 * in your items array or the number defined in the `totalItems` option.
 *
 * @param loadMoreItems This callback is invoked when more rows must be loaded. It will be used to
 *  determine when to refresh the list with the newly-loaded data. This callback may be called multiple
 *  times in reaction to a single scroll event, so it's important to memoize its arguments. If you're
 *  creating this callback inside of a functional component, make sure you wrap it in `React.useCallback()`,
 *  as well.
 * @param options
 */
A utility hook for seamlessly adding infinite scroll behavior to the `useMasonry()` hook. This
hook invokes a callback each time the last rendered index surpasses the total number of items
in your items array or the number defined in the `totalItems` option.

@param loadMoreItems This callback is invoked when more rows must be loaded. It will be used to
determine when to refresh the list with the newly-loaded data. This callback may be called multiple
times in reaction to a single scroll event, so it's important to memoize its arguments. If you're
creating this callback inside of a functional component, make sure you wrap it in `React.useCallback()`,
as well.
@param options
A utility hook for seamlessly adding infinite scroll behavior to the ` useMasonry () ` hook . This hook invokes a callback each time the last rendered index surpasses the total number of items in your items array or the number defined in the ` totalItems ` option . @param loadMoreItems This callback is invoked when more rows must be loaded . It will be used to determine when to refresh the list with the newly - loaded data . This callback may be called multiple times in reaction to a single scroll event so it ' s important to memoize its arguments . If you ' re creating this callback inside of a functional component make sure you wrap it in ` React . useCallback () ` as well . @param options
function useInfiniteLoader(loadMoreItems, options = emptyObj) {
  const {
    isItemLoaded,
    minimumBatchSize = 16,
    threshold = 16,
    totalItems = 9e9,
  } = options
  const storedLoadMoreItems = (0, _latest.default)(loadMoreItems)
  const storedIsItemLoaded = (0, _latest.default)(isItemLoaded)
  return React.useCallback(
    (startIndex, stopIndex, items) => {
      const unloadedRanges = scanForUnloadedRanges(
        storedIsItemLoaded.current,
        minimumBatchSize,
        items,
        totalItems,
        Math.max(0, startIndex - threshold),
        Math.min(totalItems - 1, (stopIndex || 0) + threshold)
      ) 
      for (let i = 0; i < unloadedRanges.length - 1; ++i)
        storedLoadMoreItems.current(
          unloadedRanges[i],
          unloadedRanges[++i],
          items
        )
    },
    [
      totalItems,
      minimumBatchSize,
      threshold,
      storedLoadMoreItems,
      storedIsItemLoaded,
    ]
  )
}
function useInfiniteLoader ( loadMoreItems , options = emptyObj ) { const { isItemLoaded , minimumBatchSize = 16 , threshold = 16 , totalItems = 9e9 , } = options const storedLoadMoreItems = ( 0 , _latest . default ) ( loadMoreItems ) const storedIsItemLoaded = ( 0 , _latest . default ) ( isItemLoaded ) return React . useCallback ( ( startIndex , stopIndex , items ) => { const unloadedRanges = scanForUnloadedRanges ( storedIsItemLoaded . current , minimumBatchSize , items , totalItems , Math . max ( 0 , startIndex - threshold ) , Math . min ( totalItems - 1 , ( stopIndex || 0 ) + threshold ) ) for ( let i = 0 ; i < unloadedRanges . length - 1 ; ++ i ) storedLoadMoreItems . current ( unloadedRanges [ i ] , unloadedRanges [ ++ i ] , items ) } , [ totalItems , minimumBatchSize , threshold , storedLoadMoreItems , storedIsItemLoaded , ] ) }
A utility hook for seamlessly adding infinite scroll behavior to the `useMasonry()` hook.
A utility hook for seamlessly adding infinite scroll behavior to the ` useMasonry () ` hook .
// The user is responsible for memoizing their loadMoreItems() function // because we don't want to make assumptions about how they want to deal // with `items`