React-admin: Each child in an array or iterator should have a unique "key" prop.

Created on 1 Feb 2018  路  7Comments  路  Source: marmelab/react-admin

I am getting error of unique key

index.js:2178 Warning: Each child in an array or iterator should have a unique "key" prop.

Check the render method of `DatagridBody`. See https://fb.me/react-warning-keys for more information.
    in TableRow (created by DatagridBody)
    in DatagridBody (created by shouldUpdate(DatagridBody))
    in shouldUpdate(DatagridBody) (created by Datagrid)
    in table (created by Table)
    in div (created by Table)
    in div (created by Table)
    in Table (created by Datagrid)
    in Datagrid (created by MuiComponent)
    in MuiComponent (at JobListAdmin.js:7)
    in div (created by List)
    in div (created by Card)
    in div (created by Paper)
    in Paper (created by Card)
    in Card (created by List)
    in div (created by List)
    in List (created by WithPermissionsFilteredChildren)
    in WithPermissionsFilteredChildren (created by getContext(WithPermissionsFilteredChildren))
    in getContext(WithPermissionsFilteredChildren) (created by getContext(getContext(WithPermissionsFilteredChildren)))
    in getContext(getContext(WithPermissionsFilteredChildren)) (created by Connect(getContext(getContext(WithPermissionsFilteredChildren))))
    in Connect(getContext(getContext(WithPermissionsFilteredChildren))) (at JobListAdmin.js:6)
    in JobList (created by Route)
    in Restricted (created by Connect(Restricted))
    in Connect(Restricted) (created by Route)
    in Route (created by CrudRoute)
    in Switch (created by CrudRoute)
    in CrudRoute (created by Route)
    in Route (created by AdminRoutes)
    in Switch (created by AdminRoutes)
    in AdminRoutes (created by Connect(AdminRoutes))
    in Connect(AdminRoutes) (created by getContext(Connect(AdminRoutes)))
    in getContext(Connect(AdminRoutes)) (created by Layout)
    in div (created by Layout)
    in div (created by Layout)
    in div (created by Layout)
    in div (created by Layout)
    in MuiThemeProvider (created by Layout)
    in Layout (created by WithWidth)
    in EventListener (created by WithWidth)
    in WithWidth (created by Connect(WithWidth))
    in Connect(WithWidth) (created by Route)
    in Route (created by Admin)
    in Switch (created by Admin)
    in div (created by Admin)
    in Router (created by ConnectedRouter)
    in ConnectedRouter (created by Admin)
    in TranslationProvider (created by withContext(TranslationProvider))
    in withContext(TranslationProvider) (created by Connect(withContext(TranslationProvider)))
    in Connect(withContext(TranslationProvider)) (created by Admin)
    in Provider (created by Admin)
    in Admin (created by withContext(Admin))
    in withContext(Admin) (at Admin.js:12)
    in Administrator (created by Route)
    in Route (at App.js:27)
    in Switch (at App.js:18)
    in div (at App.js:17)
    in Router (created by BrowserRouter)
    in BrowserRouter (at App.js:16)
    in div (at App.js:15)
    in App (at index.js:12)
    in Router (created by BrowserRouter)
    in BrowserRouter (at index.js:11)

my component looks like this

import React from 'react'
import { List, Datagrid, TextField, SaveButton } from 'admin-on-rest'

export const JobList = props => {
  return (
    <List {...props} title="List of Jobs">
      <Datagrid>
        <TextField source="organisation_name" />
        <TextField source="job_title" />
        <TextField source="employment_type" />
        <TextField source="job_location" />
        <TextField source="salary_range" />
        <TextField source="external_link" />
        <SaveButton label="Accept" />
        <SaveButton label="Decline" />
      </Datagrid>
    </List>
  )
}

Most helpful comment

I have an _id field in my rest api, but admin on rest expects there should be primary key field id so i have to convert that _id field to id

All 7 comments

Thanks for reporting this issue. However, there is an issue template: please use it next time.

What versions of admin-on-rest and react are you using ?

I am using react 16.2.0 and admin-on-rest 1.3.4

@djhi what could be the issue ?

This should be the reason - https://marmelab.com/admin-on-rest/FAQ.html#can-i-have-custom-identifiers-primary-keys-for-my-resources

Can you elaborate ?

I have an _id field in my rest api, but admin on rest expects there should be primary key field id so i have to convert that _id field to id

@mbj36 can you add your solution here. It would be very helpful.

cause I have tried this

export const LoginCredentialList = (props) => (

    <List {...props}>
        <Datagrid key={props.loginCredentialID}>
                 ...
        </Datagrid>
    </List>
);

And it doesn't work

Was this page helpful?
0 / 5 - 0 ratings

Related issues

9747749366 picture 9747749366  路  3Comments

aserrallerios picture aserrallerios  路  3Comments

mbj36 picture mbj36  路  3Comments

kopax picture kopax  路  3Comments

yangjiamu picture yangjiamu  路  3Comments