4

I am using https://github.com/strml/react-grid-layout to create a layout of items which I can resize and move. The problem I'm having has been raised in multiple issues (below) against the repo with little assistance.

  1. https://github.com/STRML/react-grid-layout/issues/806
  2. https://github.com/STRML/react-grid-layout/issues/299

Here is the bit of code that works fine.

<ResponsiveGridLayout
    layouts={this.state.layouts}
    autoSize={autosize}
    breakpoints={breakpoints}
    onLayoutChange={(layout, newLayout) =>
        this.onLayoutChange(layout, newLayout)}>
    <div key="1">...</div>
    <div key="2">...</div>
    <div key="3">...</div>
</ResponsiveGridLayout>

I would like the ability to nest a custom component within <ResponsiveGridLayout> like so. Where <CustomComponent /> contains other boxes that can interact.

<ResponsiveGridLayout
    layouts={this.state.layouts}
    autoSize={autosize}
    breakpoints={breakpoints}
    onLayoutChange={(layout, newLayout) =>
        this.onLayoutChange(layout, newLayout)}>
    <div key="1">...</div>
    <CustomComponent />
</ResponsiveGridLayout>

Here is a basic reproduction of the problem I'm having.

https://stackblitz.com/edit/react-rncnqr

Thanks in advance!

CWSites
  • 1,428
  • 1
  • 19
  • 34

1 Answers1

0

You should add key props to CustomComponent

<ResponsiveGridLayout
    layouts={this.state.layouts}
    autoSize={autosize}
    breakpoints={breakpoints}
    onLayoutChange={(layout, newLayout) =>
        this.onLayoutChange(layout, newLayout)}>
    <div key="1">...</div>
    <CustomComponent key="2" />
</ResponsiveGridLayout>