0

I encountered an error earlier:
Warning: Encountered two children with the same key,project. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

This error was coming from a Grommet DataTable I have been using. The issue is on my table, the first column is "type", which can have one of two options: project, or task. Grommet automatically takes the first column as the key, which is not what I want since the keys will become duplicates.

I have thoroughly gone through Grommets documentation and have attempted to input the primary key like they have instructed here:

https://v2.grommet.io/datatable#primaryKey

My first attempt was using the primaryKey as they instructed, see first attempt in code below.

My second attempt is I inputted the data._id as a column, and set primary to true. This works, but I don't want the data._id to display in my table, I just want to set it as the key.


`<DataTable
    sortable={true}
//this is what I attempted but nothing happened
    primaryKey={data._id}
    columns={columns}
    data={data}
/>`


I want to set the key to data._id, because it is a unique identifier, however, I do not want data._id to display in my table.

Any suggestions would be greatly appreciated.

eoan
  • 111
  • 1
  • 9
  • it seems that the lib lacks support for your case :). My suggestion is to go with your attempt 2 and use css to hide that column – duc mai Apr 14 '19 at 17:45

1 Answers1

1

primaryKey needs to be a string, so in this case, it would be:

`<DataTable
    sortable={true}
    primaryKey="_id"
    columns={}
  />`
eoan
  • 111
  • 1
  • 9