Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda