Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Previous page pagination in React and Firestore

I am calling data from firestore and paginating them. This is my query:

const tradesRef = firebase
    .firestore()
    .collection("trades")
    .orderBy("quoteQty", "desc")
    .where("quoteQty", ">", 5000)
    .limit(12);

useEffect(() => {
    tradesRef.get().then((collections) => {
      const tradesData = collections.docs.map((trade) => trade.data());
      const lastDoc = collections.docs[collections.docs.length - 1];
      setTrades(tradesData);
      setLastTrades(lastDoc);
    });
    setDataLoading(false);
  }, []);

I am using this function to get the next 12 trades:

const fetchMore = () => {
    tradesRef
      .startAfter(lastTrades)
      .get()
      .then((collections) => {
        const tradesData = collections.docs.map((trade) => trade.data());
        const lastDoc = collections.docs[collections.docs.length - 1];
        setTrades(tradesData);
        setLastTrades(lastDoc);
      });
  };

I am trying to give a previous page option but can not figure out how to go to the previous page. So far I have tried this which does not work:

const fetchPrevious = () => {
    tradesRef
      .endBefore(lastIndex)
      .limitToLast(12)
      .get()
      .then((collections) => {
        const tradesData = collections.docs.map((trade) => trade.data());
        const lastDoc = collections.docs[collections.docs.length - 1];
        setTrades(tradesData);
        setLastTrades(lastDoc);
      });
  };

Any suggestions on how can I make the previous button work?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!