@@ -147,7 +147,7 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
147147 route,
148148 params,
149149 opts,
150- placeholder,
150+ placeholder = ( p : APIPlaceholderProps ) => h ( Spinner ) ,
151151 className,
152152 itemComponent = JSONView ,
153153 loadingPlaceholder = LoadingPlaceholder ,
@@ -160,7 +160,15 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
160160 delay,
161161 } = props ;
162162 const { get } = useAPIActions ( ) ;
163- const { getCount, getNextParams, getItems, hasMore } = props ;
163+ const {
164+ getCount = ( ) => null ,
165+ getNextParams = ( response , params ) => {
166+ const lastPage = params . page ?? 0 ;
167+ return { ...params , page : lastPage + 1 } ;
168+ } ,
169+ getItems = ( d ) => d ,
170+ hasMore = ( d ) => true ,
171+ } = props ;
164172
165173 const initialState : ScrollState < T > = {
166174 items : initialItems ,
@@ -179,13 +187,6 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
179187
180188 const loadingRef = useRef ( false ) ;
181189
182- const mountedRef = useRef ( true ) ;
183- useEffect ( ( ) => {
184- return ( ) => {
185- mountedRef . current = false ;
186- } ;
187- } , [ ] ) ;
188-
189190 const loadPage = useCallback (
190191 async ( action : LoadPage < T > ) => {
191192 if ( loadingRef . current ) return ; // Prevent concurrent loads
@@ -195,7 +196,6 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
195196
196197 try {
197198 const res = await get ( route , action . params , opts ) ;
198- if ( ! mountedRef . current ) return ;
199199
200200 const itemVals = getItems ( res ) ;
201201 const nextParams = getNextParams ( res , action . params ) ;
@@ -215,7 +215,7 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
215215 } ,
216216 } ) ;
217217 } catch ( error ) {
218- if ( ! mountedRef . current ) return ;
218+ console . error ( "Error loading page:" , error ) ;
219219 action . dispatch ( {
220220 type : "update-state" ,
221221 spec : { error : { $set : error } , isLoadingPage : { $set : null } } ,
@@ -298,21 +298,4 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
298298 ) ;
299299}
300300
301- InfiniteScrollView . defaultProps = {
302- hasMore ( ) {
303- return true ;
304- } ,
305- getItems ( d ) {
306- return d ;
307- } ,
308- getCount ( ) {
309- return null ;
310- } ,
311- getNextParams ( response , params ) {
312- const lastPage = params . page ?? 0 ;
313- return { ...params , page : lastPage + 1 } ;
314- } ,
315- placeholder : ( p : APIPlaceholderProps ) => h ( Spinner ) ,
316- } ;
317-
318301export { InfiniteScrollView } ;
0 commit comments