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 get the items when swapping muuri-react?

I am trying to use muuri-react to build a masonry gallery that supports videos, images, doc and pdf. On the backend i am storing the position of the item when the user drags it to some position so i want to get the two item when they swap so i can send the updated positions to the backend. Looking at this example i couldn't figure out how can i do that i didn't find anything in the documentation either

<MuuriComponent
  dragEnabled
  dragFixed
  sort={sort}
  dragSortPredicate={{
    action: "swap"
  }}
  dragSortHeuristics={{
    sortInterval: 0
  }}
>
  {items}
</MuuriComponent>

I want to be able to do something like this

  const onSortEnd = ({ oldIndex, newIndex }) => {
setSwap([
  {
    id: items[oldIndex].id,
    // make sure to assign old indexes ID to new order
    position: newIndex,
  },
  {
    id: items[newIndex].id,
    // make sure to assign new indexes ID to old order
    position: oldIndex,
  },
])

const array = items
const tmp = array[newIndex]
tmp.position = oldIndex
array[newIndex] = array[oldIndex]
array[newIndex].position = newIndex
array[oldIndex] = tmp
setItems(array)

}

like we do in react-sortable-hoc

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!