@@ -77,7 +77,7 @@ export function useInfiniteCollection<T = any>(resourceLike: ResourceLike<any>,
7777
7878 const rel = options ?. rel || 'item' ;
7979
80- const items = useRef < Resource < T > [ ] > ( [ ] ) ;
80+ const [ items , setItems ] = useState < Resource < T > [ ] > ( [ ] ) ;
8181
8282 // Are there more pages?
8383 const nextPageResource = useRef < Resource | null > ( null ) ;
@@ -102,7 +102,7 @@ export function useInfiniteCollection<T = any>(resourceLike: ResourceLike<any>,
102102
103103 if ( ! bc . loading ) {
104104 // The 'base collection' has stopped loading, so lets set the first page.
105- items . current = bc . resourceState . followAll ( rel ) ;
105+ setItems ( bc . resourceState . followAll ( rel ) ) ;
106106 nextPageResource . current = bc . resourceState . links . has ( 'next' ) ? bc . resourceState . follow ( 'next' ) : null ;
107107 setLoading ( false ) ;
108108 }
@@ -136,10 +136,10 @@ export function useInfiniteCollection<T = any>(resourceLike: ResourceLike<any>,
136136 nextPageResource . current = nextPageState . links . has ( 'next' ) ? nextPageState . follow ( 'next' ) : null ;
137137
138138 // Add new resources to page data
139- items . current = [
140- ...items . current ,
139+ setItems ( [
140+ ...items ,
141141 ...nextPageState . followAll ( rel )
142- ] ;
142+ ] ) ;
143143
144144 } catch ( err :any ) {
145145 error . current = err ;
@@ -151,7 +151,7 @@ export function useInfiniteCollection<T = any>(resourceLike: ResourceLike<any>,
151151 return {
152152 loading : bc . loading || loading ,
153153 error : bc . error ?? error . current ?? null ,
154- items : items . current ,
154+ items,
155155 hasNextPage : nextPageResource . current !== null ,
156156 loadNextPage,
157157 } ;
0 commit comments