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

309
Views
Using useSortableData based on useMemo() after data update in React app

I've made application based on this example

https://codesandbox.io/embed/table-sorting-example-ur2z9?fontsize=14&hidenavigation=1&theme=dark

But also I need data update in table (adding, removing)

I use

const { items, requestSort, sortConfig } = useSortableData(data.items, sortObj);
const [datarows, setDatarows] = useState({})

useEffect(() => {
setDatarows(items)
});

const updateData = (row, useropt) => {
...
/* here fetching some data */
...
setDatarows(rows2);
}

But after data update useSortableData function is sorting initially added data How to make useSortableData use updated data?

I've tried

const [datarows, setDatarows] = useState(data.items)
const { items, requestSort, sortConfig } = useSortableData(datarows, sortObj);

But in this case I get

Unhandled Runtime Error

TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method.

Thanks

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

0

Looking at the code you provided it looks like useSortableData is has items as a dependency in the useMemo of the sortedItems. Meaning that any changes to data.items will result in a recalculation of the sorted items.

You have not provided the piece of code from where you get data.items, therefore this is the extent of what I can help with

enter image description here

about 4 years ago · Juan Pablo Isaza Report

0

Solved.

Data loading and changing left in main Component. The table and sorting const { items, requestSort, sortConfig } = useSortableData(data.items, sortObj); moved to other component

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!