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

160
Views
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 answers
Answer question

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 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!