material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Duplicated Cell keys when rendering more then one table in the same component

Open LuanScudeler opened this issue 6 years ago • 5 comments

Hi,

I'm redering several tables in the same component and I'm getting warnings like below for every cell in the tables and I think is impacting perfomance:

Warning: Encountered two children with the same key, "cell-1-5".

Is there a way to provide my own unique keys for the Cell comopents so I can make them different from table to table?

I've tried by overriding the Cell component and providing my own key but it only goes to the MTableCell component.

components={{ Cell: (props) => ( <MTableCell key={uuidv4()} {...props} /> ), }}

image

LuanScudeler avatar May 31 '20 04:05 LuanScudeler

@LuanScudeler

I'm not quite sure how to reproduce this.. I rendered 10 tables in the same component but did not receive that error. What do you mean when you say "rendering several tables in the same component"?

Check out a demo here

import React, { useState } from "react";
import { render } from "react-dom";
import MaterialTable from "material-table";
import tableIcons from "./TableIcons.js";

const rando = max => Math.floor(Math.random() * max);

const words = ["Paper", "Rock", "Scissors"];

const rawData = [];
for (let i = 0; i < 100; i++) {
  rawData.push({ id: rando(300), word: words[i % words.length] });
}

const columns = [
  { title: "Id", field: "id" },
  { title: "Word", field: "word" }
];

const App = () => {
  const [data, setData] = useState(rawData);

  return ( 
    <React.Fragment>
      {Array.from({ length: 10 }).map(() => (
        <div>
          <MaterialTable
            data={data}
            columns={columns}
            title="Starter Template"
            icons={tableIcons}
          />
        </div>
      ))}
    </React.Fragment> );
};

render(<App />, document.querySelector("#root"));

matthewoestreich avatar May 31 '20 09:05 matthewoestreich

Hi @oze4, thanks for looking into this.

I'm redering just like you did. Thats true, I don't see it throwing errors of duplicated keys in your demo. I don't get why it's happening in my case.

The thing I have different in my case is custom renders for most of my columns, but I don't know if that should matter.

I'm trying to tweak your demo to see if I can get the error to show up, but I didn't have success yet.

LuanScudeler avatar Jun 04 '20 02:06 LuanScudeler

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Sep 02 '20 03:09 stale[bot]

The problem is present when adding multiple tables in same component, and one of the tables has actions, or a rendered column.

cargallo avatar Jan 13 '22 12:01 cargallo

The problem is present when adding multiple tables in same component, and one of the tables has actions, or a rendered column.

@cargallo

you were right man, thanks a lot!

piotr-kwiatek avatar Jul 17 '24 11:07 piotr-kwiatek