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

114
Views
React Add filtering on pagination

I have a product page sorted by title. Sorting works, everything is fine, but when pagination occurs, new items are loaded without sorting. How to fix it?

const Grid = ({filter, countOnRow, totalCount, products}) => {
const [fetching, setFetching] = useState(true)
const [total, setTotal] = useState(totalCount)
const [startPage, setStartPage] = useState(0)
const [produs, setProdus] = useState([])
const [okay, setOkay] = useState(false)
const [selectedSort, setSelectedSort] = useState('')

useEffect(()=>{
    if(fetching){
        setProdus([...produs, ...products.slice(startPage,total)])
        setStartPage(total)
        setTotal(total+total)
        setFetching(false )

    }
}, [fetching])

useEffect(()=>{
    document.addEventListener('scroll', scrollHadnler);

    return function(){
        document.removeEventListener('scroll', scrollHadnler)
    };
}, [])

const scrollHadnler=(e)=>{
    if(e.target.documentElement.scrollHeight-(e.target.documentElement.scrollTop+window.innerHeight)<100){
        setFetching(true)
        
    }
}
const sortByName = (sort) => {
    setSelectedSort(sort)
    setProdus([...produs].sort((a,b) => a[sort].localeCompare(b[sort])))
    setOkay(!okay)
}

How can I implement the filtering to persist after pagination.

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!