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

210
Views
How to wrap MUI data grid rows and columns in useRef (to fix infinite loop in onSortModelChange)

I have the same problem as the question below. A comment said to use useRef to wrap rows and columns and use its .current value. How do I do that??

Material-UI Data Grid onSortModelChange Causing an Infinite Loop

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I could not figure out the useRef, and seeing this post is a month old you have most likely solved it by now. But for others like myself googling for a solution, here is how I solved the problem:

    const [sortModel, setSortModel] = useState<GridSortModel>([
    {
        field: 'created',
        sort: 'desc',
    },
]);

const handleSortChange = (model: GridSortModel) => {
    /* if statement to prevent the infinite loop by confirming model is 
     different than the current sortModel state */
    if (JSON.stringify(model) !== JSON.stringify(sortModel)) {
        setSortModel(model);
    }
};

<DataGrid
rows={taskData}
columns={myWorkColumns}
sortModel={sortModel}
onSortModelChange={(model) => handleSortChange(model)}
/>
about 4 years ago · Juan Pablo Isaza Report
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!