1- import { useContext , useEffect , useCallback , useRef , useState } from 'react' ;
1+ import {
2+ useContext ,
3+ useEffect ,
4+ useCallback ,
5+ useRef ,
6+ useMemo ,
7+ useState ,
8+ } from 'react' ;
29
310import { PluginContext } from './Context' ;
411import {
@@ -81,7 +88,7 @@ export function useElementColumns(id: string): WorkbookElementColumns {
8188}
8289
8390/**
84- * Provides the latest data values from corresponding sheet
91+ * Provides the latest data values from corresponding sheet (max 25_000)
8592 * @param {string } id Sheet ID to get element data from
8693 * @returns {WorkbookElementData } Element Data for corresponding sheet, if any
8794 */
@@ -98,6 +105,33 @@ export function useElementData(id: string): WorkbookElementData {
98105 return data ;
99106}
100107
108+ /**
109+ * Provides the latest data values from corresponding sheet with a callback to
110+ * fetch more in chunks of 25_000 data points
111+ * @param {string } id Sheet ID to get element data from
112+ * @returns {WorkbookElementData } Element Data for corresponding sheet, if any
113+ */
114+ export function usePaginatedElementData (
115+ id : string ,
116+ ) : [ WorkbookElementData , ( ) => void ] {
117+ const client = usePlugin ( ) ;
118+ const [ data , setData ] = useState < WorkbookElementData > ( { } ) ;
119+
120+ const loadMore = useCallback ( ( ) => {
121+ if ( id ) {
122+ client . elements . fetchMoreElementData ( id ) ;
123+ }
124+ } , [ id ] ) ;
125+
126+ useEffect ( ( ) => {
127+ if ( id ) {
128+ return client . elements . subscribeToElementData ( id , setData ) ;
129+ }
130+ } , [ client , id ] ) ;
131+
132+ return [ data , loadMore ] ;
133+ }
134+
101135/**
102136 * Provides the latest value for entire config or certain key within the config
103137 * @param {string } key Key within Plugin Config, optional
0 commit comments