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

164
Visualizações
How to save the position of an element after dragging and changing its position in react js

I used the kanban library for Drag and Drop and now I want their location to be saved after dragging and dropping. After the page is refreshed, they should be in the saved position

I have not tried the cookie yet. What do you guys suggest? Thansk for your help

import ReactDOM from "react-dom";
import Board, { moveCard } from "@lourenci/react-kanban";
import "@lourenci/react-kanban/dist/styles.css";

function ControlledBoard() {
    // You need to control the state yourself.
    const [controlledBoard, setBoard] = useState(board);

    function handleCardMove(_card, source, destination) {
        const updatedBoard = moveCard(controlledBoard, source, destination);
        setBoard(updatedBoard);
    }

    return (
        <Board onCardDragEnd={handleCardMove} disableColumnDrag>
            {controlledBoard}
        </Board>
    );
}

function UncontrolledBoard() {
    return (
        <>
        <Board
            allowRemoveLane
            allowRenameColumn
            disableColumnDrag
            allowRemoveCard
            onLaneRemove={console.log}
            onCardRemove={console.log}
            onLaneRename={console.log}
            initialBoard={board}
            allowAddCard
            onNewCardConfirm={draftCard => ({
                id: new Date().getTime(),
                ...draftCard
            })}
            onCardNew={console.log}
        />
        </>
    );
}

function App() {
    return (
        <>
            <h4>Example of an uncontrolled board</h4>
            <UncontrolledBoard />
            <h4>Example of a controlled board</h4>
            <p>Just the card moving is implemented in this demo.</p>
            <p>
                In this kind of board, you can do whatever you want. We just mirror your
                board state.
            </p>
            <ControlledBoard />
        </>
    );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);```

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Storing the location of each instance, as an object with source and destination, in localStorage can solve the issue

localStorage.setItem(
      `instance`,
      JSON.stringify({
        board: {
           source: value,
           destination:value
        },
      })
    );
about 4 years ago · Juan Pablo Isaza Relatório
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