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

316
Views
Why didn't the location of React-grid-layout change?

Why didn't the location of React-grid-layout change?

I think click the button the positions of 1 and 2 should be swapped.

Thank you so much for letting me know !!

below is the code I am using for this

import React from "react";
import ReactDOM from "react-dom";
import RGL, { WidthProvider } from "react-grid-layout";

import "./styles.css";

const ReactGridLayout = WidthProvider(RGL);

let idCounter = 0;

class MinMaxLayout extends React.PureComponent {
  static defaultProps = {
    isDraggable: true,
    isResizable: true,
    items: 5,
    rowHeight: 30,
    preventCollision: false,
    cols: 12
  };

  state = {
    layout: [
      { x: 0, y: 0, w: 3, h: 3, i: "1" },
      { x: 0, y: 1, w: 3, h: 3, i: "2" }
    ]
  };

  render() {
    return (
      <React.Fragment>
        <button onClick={this.addNewItem}>Add item</button>
        <ReactGridLayout {...this.props}>
          {this.state.layout.map((item) => {
            console.log(item);
            return (
              <div key={item.i} data-grid={item}>
                <span>{item.i}</span>
                <span>{idCounter++}</span>
              </div>
            );
          })}
        </ReactGridLayout>
      </React.Fragment>
    );
  }

  addNewItem = () => {
    this.setState({
      ...this.state,
      layout: [
        { x: 0, y: 1, w: 3, h: 3, i: "1" },
        { x: 0, y: 0, w: 3, h: 3, i: "2" }
      ]
    });
  };
}

module.exports = MinMaxLayout;

if (require.main === module) {
  require("../test-hook.jsx")(module.exports);
}

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

https://codesandbox.io/s/react-grid-layout-forked-u3q4x?file=/src/index.js:0-1673

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!