@diana-ui/hooks
Advanced tools
Comparing version 0.1.24 to 0.1.25
@@ -6,4 +6,5 @@ /// <reference types="react" /> | ||
intersectionOptions?: IntersectionObserverInit; | ||
wrappedRef?: boolean; | ||
} | ||
declare function useInfiniteScrollList(fullList: JSX.Element[], options?: IOptions): JSX.Element[]; | ||
export default useInfiniteScrollList; |
@@ -11,6 +11,4 @@ var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
function useInfiniteScrollList(fullList, options) { | ||
var _a = useMemo(function () { return options !== null && options !== void 0 ? options : {}; }, [ | ||
options | ||
]), _b = _a.limit, limit = _b === void 0 ? 10 : _b, _c = _a.dependencies, dependencies = _c === void 0 ? [] : _c, intersectionOptions = _a.intersectionOptions; | ||
var _d = useState(fullList.slice(0, limit)), list = _d[0], setList = _d[1]; | ||
var _a = useMemo(function () { return options !== null && options !== void 0 ? options : {}; }, [options]), _b = _a.limit, limit = _b === void 0 ? 10 : _b, _c = _a.dependencies, dependencies = _c === void 0 ? [] : _c, intersectionOptions = _a.intersectionOptions, _d = _a.wrappedRef, wrappedRef = _d === void 0 ? false : _d; | ||
var _e = useState(fullList.slice(0, limit)), list = _e[0], setList = _e[1]; | ||
useEffect(function () { | ||
@@ -38,3 +36,3 @@ setList(fullList.slice(0, limit)); | ||
if (index === list.length - 1 && list.length !== fullList.length) { | ||
var props = item.type.WrappedComponent ? { wrappedRef: ref } : { ref: ref }; | ||
var props = wrappedRef ? { wrappedRef: ref } : { ref: ref }; | ||
return React.cloneElement(item, props); | ||
@@ -44,5 +42,5 @@ } | ||
}); | ||
}, [list, fullList]); | ||
}, [list, fullList, wrappedRef]); | ||
return memoList; | ||
} | ||
export default useInfiniteScrollList; |
@@ -6,4 +6,5 @@ /// <reference types="react" /> | ||
intersectionOptions?: IntersectionObserverInit; | ||
wrappedRef?: boolean; | ||
} | ||
declare function useInfiniteScrollList(fullList: JSX.Element[], options?: IOptions): JSX.Element[]; | ||
export default useInfiniteScrollList; |
import React, { useEffect, useState, useRef, useMemo, useCallback } from "react"; | ||
import useIntersectionObserver from "./useIntersectionObserver"; | ||
function useInfiniteScrollList(fullList, options) { | ||
const { limit = 10, dependencies = [], intersectionOptions } = useMemo(() => options !== null && options !== void 0 ? options : {}, [ | ||
options | ||
]); | ||
const { limit = 10, dependencies = [], intersectionOptions, wrappedRef = false } = useMemo(() => options !== null && options !== void 0 ? options : {}, [options]); | ||
const [list, setList] = useState(fullList.slice(0, limit)); | ||
@@ -29,9 +27,9 @@ useEffect(() => { | ||
if (index === list.length - 1 && list.length !== fullList.length) { | ||
const props = item.type.WrappedComponent ? { wrappedRef: ref } : { ref }; | ||
const props = wrappedRef ? { wrappedRef: ref } : { ref }; | ||
return React.cloneElement(item, props); | ||
} | ||
return item; | ||
}), [list, fullList]); | ||
}), [list, fullList, wrappedRef]); | ||
return memoList; | ||
} | ||
export default useInfiniteScrollList; |
{ | ||
"name": "@diana-ui/hooks", | ||
"version": "0.1.24", | ||
"version": "0.1.25", | ||
"main": "lib/index.js", | ||
@@ -45,3 +45,3 @@ "module": "module/index.js", | ||
}, | ||
"gitHead": "007c97484702019d0c1f2d899d941ec1082fffdd" | ||
"gitHead": "ae6eb4bd95d1fc4ec75486caaca674197742b950" | ||
} |
16499
337