MCPcopy Index your code
hub / github.com/TanStack/query / MyComponent

Function MyComponent

packages/react-query/src/__tests__/useInfiniteQuery.test.tsx:1799–1825  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1797 }
1798
1799 function MyComponent() {
1800 useTrackRenders()
1801 const fetchCountRef = React.useRef(0)
1802 const query = useInfiniteQuery({
1803 queryFn: ({ pageParam }) =>
1804 fetchItems(pageParam, fetchCountRef.current++),
1805 getNextPageParam: (lastPage) => lastPage.nextId,
1806 initialPageParam: 0,
1807 queryKey: key,
1808 })
1809 const data = React.use(query.promise)
1810 return (
1811 <>
1812 {data.pages.map((page, index) => (
1813 <React.Fragment key={page.ts}>
1814 <div>
1815 <div>Page: {index + 1}</div>
1816 </div>
1817 {page.items.map((item) => (
1818 <p key={item}>Item: {item}</p>
1819 ))}
1820 </React.Fragment>
1821 ))}
1822 <button onClick={() => query.fetchNextPage()}>fetchNextPage</button>
1823 </>
1824 )
1825 }
1826
1827 function Page() {
1828 useTrackRenders()

Callers

nothing calls this directly

Calls 3

fetchNextPageMethod · 0.80
fetchItemsFunction · 0.70
useInfiniteQueryFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…