@@ -28,7 +28,15 @@ function useInfiniteLoader(_ref) {
28
28
_ref$hasMore = _ref . hasMore ,
29
29
hasMore = _ref$hasMore === void 0 ? false : _ref$hasMore ,
30
30
_ref$initialise = _ref . initialise ,
31
- initialise = _ref$initialise === void 0 ? true : _ref$initialise ;
31
+ initialise = _ref$initialise === void 0 ? true : _ref$initialise ,
32
+ _ref$rootMargin = _ref . rootMargin ,
33
+ rootMargin = _ref$rootMargin === void 0 ? "100px 0px 0px 0px" : _ref$rootMargin ,
34
+ _ref$threshold = _ref . threshold ,
35
+ threshold = _ref$threshold === void 0 ? 0 : _ref$threshold ;
36
+
37
+ if ( typeof loadMore !== "function" ) {
38
+ throw new TypeError ( "useInfiniteLoader: loadMore must be a function and is required" ) ;
39
+ }
32
40
33
41
var loaderRef = _react . default . useRef ( null ) ;
34
42
@@ -53,8 +61,8 @@ function useInfiniteLoader(_ref) {
53
61
loadMore ( page . current ) ;
54
62
page . current += 1 ;
55
63
} , {
56
- rootMargin : "20px 0px" ,
57
- threshold : 0.01
64
+ rootMargin : rootMargin ,
65
+ threshold : threshold
58
66
} ) ;
59
67
60
68
if ( loaderRef . current ) {
@@ -66,10 +74,10 @@ function useInfiniteLoader(_ref) {
66
74
observer . current . disconnect ( ) ;
67
75
observer . current = undefined ;
68
76
} ;
69
- } , [ hasMore , loadMore , page ] ) ;
77
+ } , [ hasMore , loadMore , page , initialise ] ) ;
70
78
71
79
return {
72
80
loaderRef : loaderRef ,
73
- page : page
81
+ page : page . current
74
82
} ;
75
83
}
0 commit comments