@@ -174,7 +174,7 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
174174 route,
175175 params,
176176 opts,
177- placeholder,
177+ placeholder = ( p : APIPlaceholderProps ) => h ( Spinner ) ,
178178 className,
179179 itemComponent = JSONView ,
180180 loadingPlaceholder = LoadingPlaceholder ,
@@ -187,7 +187,15 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
187187 delay,
188188 } = props ;
189189 const { get } = useAPIActions ( ) ;
190- const { getCount, getNextParams, getItems, hasMore } = props ;
190+ const {
191+ getCount = ( ) => null ,
192+ getNextParams = ( response , params ) => {
193+ const lastPage = params . page ?? 0 ;
194+ return { ...params , page : lastPage + 1 } ;
195+ } ,
196+ getItems = ( d ) => d ,
197+ hasMore = ( d ) => true ,
198+ } = props ;
191199
192200 const initialState : ScrollState < T > = {
193201 items : initialItems ,
@@ -206,13 +214,6 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
206214
207215 const loadingRef = useRef ( false ) ;
208216
209- const mountedRef = useRef ( true ) ;
210- useEffect ( ( ) => {
211- return ( ) => {
212- mountedRef . current = false ;
213- } ;
214- } , [ ] ) ;
215-
216217 const loadPage = useCallback (
217218 async ( action : LoadPage < T > ) => {
218219 if ( loadingRef . current ) return ; // Prevent concurrent loads
@@ -222,7 +223,6 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
222223
223224 try {
224225 const res = await get ( route , action . params , opts ) ;
225- if ( ! mountedRef . current ) return ;
226226
227227 const itemVals = getItems ( res ) ;
228228 const nextParams = getNextParams ( res , action . params ) ;
@@ -242,7 +242,7 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
242242 } ,
243243 } ) ;
244244 } catch ( error ) {
245- if ( ! mountedRef . current ) return ;
245+ console . error ( "Error loading page:" , error ) ;
246246 action . dispatch ( {
247247 type : "update-state" ,
248248 spec : { error : { $set : error } , isLoadingPage : { $set : null } } ,
@@ -325,21 +325,4 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
325325 ) ;
326326}
327327
328- InfiniteScrollView . defaultProps = {
329- hasMore ( ) {
330- return true ;
331- } ,
332- getItems ( d ) {
333- return d ;
334- } ,
335- getCount ( ) {
336- return null ;
337- } ,
338- getNextParams ( response , params ) {
339- const lastPage = params . page ?? 0 ;
340- return { ...params , page : lastPage + 1 } ;
341- } ,
342- placeholder : ( p : APIPlaceholderProps ) => h ( Spinner ) ,
343- } ;
344-
345328export { InfiniteScrollView } ;
0 commit comments