score:2
infinitequeries
don't really care how your backend delivers a "cursor" to the next page, it just matters that the backend delivers something.
basically, whatever is returned from getnextpageparam
will be injected into the queryfn as pageparam
. here is an example that might fit your use-case:
const { data } = useinfinitequery(
'key',
({ pageparam }) => axios.get(myurl + '?offset=' + pageparam?.offset ?? 0),
{
getnextpageparam: (lastpage) => lastpage?.meta
}
)
the concept of a "page" is merely what ever your backend returns for a single fetch. so here, on the first fetch (for page 0), we have no pageparam, so we initalize with offset: 0
. then, we fetch with that, and the backend returns the first set of data (a page), and we extract the meta info for it (offset = 20 or whatever).
if you call fetchnextpage()
, the queryfn will be called with that meta information, so the next fetch does ?offset=20
. the backend delivers offset: 40 as meta and the infinity continues.
hope that explains it :)
Source: stackoverflow.com
Related Query
- How react Infinite Queries support with offset and limit
- How to limit the text filed length with input type number in React JS and prevent entry of E,e, -, + etc
- How to test styles and media queries rendered by a React component with Jest and/or Enzyme
- How to make infinite scroll work with react and intersection api while lazily fetching data?
- How to limit number with 0-999 and just three numbers after the comma in React
- How to test a className with the Jest and React testing library
- How to import CSS modules with Typescript, React and Webpack
- How to mock React component methods with jest and enzyme
- How to set up Babel 6 stage 0 with React and Webpack
- How do I store JWT and send them with every request using react
- How to create forms with React and Rails?
- How to make react router work with static assets, html5 mode, history API and nested routes?
- How to correctly redirect after catching authentication failure with Apollo and React
- How to use React with Typescript and SASS
- How to test a component with a nested container with React and Redux?
- React table dynamic page size but with size limit and pagination
- How to use vw and vh css with React Native
- How to test form submission in React with Jest and Enzyme? Cannot read property 'preventDefault' of undefined
- How to test snapshots with Jest and new React lazy 16.6 API
- How to navigate to another page with a smooth scroll on a specific id with react router and react scroll
- how to work with react routers and spring boot controller
- How to achieve re-useable components with React and mouse event propagation?
- How to use Django User Groups and Permissions on a React Frontend with Django Rest Framework
- How to read console.log from a mounted component with Enzyme and Jest in Create React App
- How to mock a React component lifecycle method with Jest and Enzyme?
- How safe is front end with react and redux?
- How to nest Scene and navigate with direction='vertical' in React Native Router Flux?
- How to solve, craco: *** Cannot find ESLint loader (eslint-loader). *** error with ANTd and React (2021)
- how can I test if useState hook has been called with jest and react testing library?
- How to hot reload without being redirected to root with electron-forge and react
More Query from same tag
- Using react-form to POST to an API?
- How to automatically expand the selection to the entire linked text in Draft.js?
- How to filter on-click in react three js?
- reducer function error when using redux-toolkit
- How to write if condition in table tags using ReactJS
- React useEffect Warning: Maximum update depth exceeded. Is there a way around this?
- ReactJS not displaying Django REST Framework API data
- How to customize a column in react table 7
- Jquery mouseenter and mouseleave is deprecated in Next.js, Tailwind
- How to instantly display data after an API call in react hooks
- How do I map over an object?
- react - Difference between createMuiTheme and createTheme
- Issue with MUI 5 DialogContent padding
- Warning: Each child in a list should have a unique "key" prop. Error With Nested For Loop Components
- Jquery Toggle on click of image
- How to return just the value of two numbers being added?
- React - Tree Component
- 'ResizeObserver' only refers to a type, but is being used as a value here
- Reset state = initialState not working for me in redux
- react-fine-uploader S3 upload using dynamic filename
- how to know the component rendering condition in react js
- What is the best practice to close a DropDown on a Link click in React?
- Reactjs: create table from array
- Material-UI: Select border color on hover
- Saving JS State to an unordered list
- How do I make my TableData react component reusable onClick when its only posting one under my table?
- Uncaught ReferenceError: ReservationCard is not defined
- Retrieving data with foreign keys laravel react
- How do I prevent the user from being able to add names that already exist?
- How to make a "global" component render content based on url route?