I can´t see the childs I pass to ResponsiveGridLayout tag, this library is so outdated I dont know what else to do.
I have this a few .jsx I´ll show you two of them:
import { useEffect, useState } from "react";
import { Responsive, WidthProvider } from "react-grid-layout";
import "./PrototypeComponent.css";
import "react-grid-layout/css/styles.css";
import "react-resizable/css/styles.css";
const ResponsiveGridLayout = WidthProvider(Responsive);
const LOCAL_STORAGE_KEY = "my_layouts";
const BREAKPOINT_KEY = "my_breakpoint";
const defaultLayouts = {
lg: [
{ i: "1", x: 0, y: 0, w: 4, h: 4 },
{ i: "2", x: 4, y: 0, w: 4, h: 4 },
{ i: "3", x: 8, y: 0, w: 4, h: 4 },
],
md: [],
sm: [],
};
function PrototypeComponent({ children }) {
const [layouts, setLayouts] = useState(defaultLayouts);
const [currentBreakpoint, setCurrentBreakpoint] = useState("lg");
useEffect(() => {
const savedLayouts = localStorage.getItem(LOCAL_STORAGE_KEY);
const savedBreakpoint = localStorage.getItem(BREAKPOINT_KEY);
if (savedLayouts) {
try {
const parsedLayouts = JSON.parse(savedLayouts);
setLayouts(parsedLayouts);
} catch (e) {
console.error("Error al leer layouts desde localStorage", e);
}
}
if (savedBreakpoint) {
setCurrentBreakpoint(savedBreakpoint);
}
}, []);
const handleBreakpointChange = (breakpoint) => {
setLayouts((prevLayouts) => {
if (!prevLayouts[breakpoint] || prevLayouts[breakpoint].length === 0) {
return {
...prevLayouts,
[breakpoint]: prevLayouts[currentBreakpoint] || [],
};
}
return prevLayouts;
});
setCurrentBreakpoint(breakpoint);
localStorage.setItem(BREAKPOINT_KEY, breakpoint);
};
const handleLayoutChange = (layout, allLayouts) => {
setLayouts(allLayouts);
};
useEffect(() => {
const handleBeforeUnload = () => {
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(layouts));
localStorage.setItem(BREAKPOINT_KEY, currentBreakpoint);
};
window.addEventListener("beforeunload", handleBeforeUnload);
return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
};
}, [layouts, currentBreakpoint]);
return (
<ResponsiveGridLayout
className="layout"
layouts={layouts}
breakpoints={{ lg: 1200, md: 996, sm: 768 }}
cols={{ lg: 12, md: 10, sm: 6 }}
rowHeight={100}
isDraggable
isResizable
draggableHandle=".handle"
compactType="horizontal"
preventCollision={false}
margin={[10, 10]}
containerPadding={[10, 10]}
onBreakpointChange={handleBreakpointChange}
onLayoutChange={handleLayoutChange}
>
{children}
</ResponsiveGridLayout>
);
}
export default PrototypeComponent;
Second one:
import PrototypeComponent from "./PrototypeComponent";
import Portlet from "./Portlet";
const PrototypePage = () => {
return (
<>
<PrototypeComponent>
<h1>Hola</h1>
<Portlet id="1" title="Portlet 1" src="https://www.example.com" />
<Portlet id="2" title="Portlet 2" src="https://www.example.com" />
<Portlet id="3" title="Portlet 3" src="https://www.example.com" />
</PrototypeComponent>
</>
);
};
export default PrototypePage;
This is what i see in the browser 1
It looks like there is nothing inside
I can´t see the childs I pass to ResponsiveGridLayout tag, this library is so outdated I dont know what else to do.I can´t see the childs I pass to ResponsiveGridLayout tag, this library is so outdated I dont know what else to do.