Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayField + Datagrid: if embedded data doesn't have an id, rows won't have a key and will cause a React warning #7541

Closed
nselikoff opened this issue Apr 13, 2022 · 4 comments · Fixed by #7548
Labels

Comments

@nselikoff
Copy link

What you were expecting:
Using an ArrayField + Datagrid for embedded data that doesn't have an id prop should work without console errors

What happened instead:
I get this error in the console: Warning: Each child in a list should have a unique "key" prop.

Steps to reproduce:
Given this Show component for an "album" record:

export const AlbumShow = () => (
  <Show>
    <SimpleShowLayout>
      <ArrayField source="features">
        <Datagrid>
          <TextField source="name" />
          <TextField source="value" />
        </Datagrid>
      </ArrayField>
    </SimpleShowLayout>
  </Show>
);

Where an album has embedded features that look like this (note that features don't have an id prop):

{
  "id": 0,
  "features": [
    { "name": "title", "value": "Test Album" }
  ]
}

Related code:
You can see repro this in the simple example (checked out and run locally; I don't see warnings in codesandbox's console)
Go to a post show page that has backlinks, e.g. http://localhost:8080/#/posts/12/show

Other information:
This is where the key is set based on the id, which doesn't exist in this case:

Environment

  • React-admin version: 4.0.0
  • Last version that did not exhibit the issue (if applicable):
  • React version: 18.0.0
  • Browser: Chrome
  • Stack trace (in case of a JS error):
@WiXSL WiXSL added the bug label Apr 14, 2022
@WiXSL
Copy link
Contributor

WiXSL commented Apr 14, 2022

Reproduced. Thanks!

@WiXSL
Copy link
Contributor

WiXSL commented Apr 14, 2022

Note that in version 4, you have to pass bulkActionButtons={false} in a Datagrid inside an ArrayField.
This is clarified in the Upgrade guide.
And I'm fixing the Show example as well #7547

@WiXSL
Copy link
Contributor

WiXSL commented Apr 14, 2022

Fixed by #7548

@nselikoff
Copy link
Author

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants