Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
function messes order up when hovering over item using drag and drop react-dnd

I have this really annoying issue, where a function runs twice and messes everything up because of it.

I have created a drag and drop, and I do that for tasks in stages. You can move a task around within a stage, but also move from one stage to another. The function is built the way that, if start item and and destination item are start < item <= destination then the items between will move their order number -1, if it is start > item >= destination then it is +1, all other instances it is +0, so not updated at all.

Now the issue is, the while I am moving one item to another item, the function runs. on the first run, it is updated corecctly, but on the second run, it takes the updated values and updates them again

So if I have this array [1, 2, 3] and I move 1 to 3, they should update like that

1 -> 3 (becomes destination order, so 3)
2 -> 1 (is start < current <= destination, so 2 - 1)
3 -> 2 (is start < current <= destination, so 3 - 1)

But then it updates again, and the end result is like this

1 -> 3 -> 3
2 -> 1 -> 0
3 -> 2 -> 1

or something like this

1 -> 3 -> 3
2 -> 1 -> 0
3 -> 2 -> 0

wherer two items have the same order, or another value, like -1. It is very annoying and messing everything up. I have no idea how to correct this behaviour.

Sandbox: https://codesandbox.io/s/drag-and-drop-order-issue-ikhyo?file=/src/Task.store.js:2195-2265 You can play around in the preview, the drag and drop works, but with the issue described above.

Function is found in Task.store.js:88

One guess that I have, is that while I am still holding the item, it also still holds the state it originally had.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda