diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 928eb46f81d..4a91396cae8 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -449,6 +449,22 @@ We've changed the implementation of ``, the companion child ``` +## `` Components No Longer Receive Any Props + +An undocumented features allowed datagrid expand panels to read the current resource, record, and id from their props. This is no longer the case in v5, as expand panels are now rendered without props by ``. + +If you used these props in your expand components, you'll have to use the `useRecordContext` hook instead: + +```diff +-const PostExpandPanel = ({ record, resource, id }) => { ++const PostExpandPanel = () => { ++ const record = useRecordContext(); ++ const resource = useResourceContext(); ++ const id = record?.id; + // ... +} +``` + ## `` no longer passes a `getSource` function When using `` inside an ``, the child function no longer receives a `getSource` callback. We've made all Input components able to work seamlessly inside an ``, so it's no longer necessary to transform their source with `getSource`: diff --git a/examples/simple/src/posts/PostList.tsx b/examples/simple/src/posts/PostList.tsx index 8a976290f53..3de23c0e5e6 100644 --- a/examples/simple/src/posts/PostList.tsx +++ b/examples/simple/src/posts/PostList.tsx @@ -30,6 +30,7 @@ import { TextField, TextInput, TopToolbar, + useRecordContext, useTranslate, } from 'react-admin'; // eslint-disable-line import/no-unresolved @@ -147,9 +148,10 @@ const rowClick = (_id, _resource, record) => { return 'show'; }; -const PostPanel = ({ record }) => ( -
-); +const PostPanel = () => { + const record = useRecordContext(); + return
; +}; const tagSort = { field: 'name.en', order: 'ASC' } as const; diff --git a/examples/simple/src/users/UserEditEmbedded.tsx b/examples/simple/src/users/UserEditEmbedded.tsx index 90e0256793c..d2d44196dea 100644 --- a/examples/simple/src/users/UserEditEmbedded.tsx +++ b/examples/simple/src/users/UserEditEmbedded.tsx @@ -1,20 +1,30 @@ /* eslint react/jsx-key: off */ import * as React from 'react'; import PropTypes from 'prop-types'; -import { Edit, Identifier, SimpleForm, TextInput, required } from 'react-admin'; +import { + Edit, + SimpleForm, + TextInput, + required, + useRecordContext, +} from 'react-admin'; -const UserEditEmbedded = ({ id }: { id?: Identifier }) => ( - /* Passing " " as title disables the custom title */ - - - - - -); +const UserEditEmbedded = () => { + const record = useRecordContext(); + if (!record) return null; + return ( + /* Passing " " as title disables the custom title */ + + + + + + ); +}; UserEditEmbedded.propTypes = { record: PropTypes.object, diff --git a/packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx b/packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx index bbb72f68466..70a4ebd44e5 100644 --- a/packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx +++ b/packages/ra-ui-materialui/src/list/datagrid/DatagridRow.tsx @@ -221,19 +221,9 @@ const DatagridRow: FC = React.forwardRef((props, ref) => { > {isElement(expand) - ? cloneElement(expand as React.ReactElement, { - // @ts-ignore - record, - resource, - id: String(id), - }) + ? expand : createElement( - expand as React.FunctionComponent, - { - record, - resource, - id: String(id), - } + expand as React.FunctionComponent )}