Skip to content

Commit 81984ad

Browse files
authored
Merge pull request #8855 from marmelab/doc-show-aside
[Doc] Fix Show documentation misses the `aside` prop
2 parents d20e8b2 + 54eb7f1 commit 81984ad

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/Show.md

+47
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ That's enough to display the post show view:
5656
## Props
5757

5858
* [`actions`](#actions): override the actions toolbar with a custom component
59+
* [`aside`](#aside): aside element
5960
* `className`: passed to the root component
6061
* [`children`](#layout): the components that render the record fields
6162
* [`component`](#component): overrides the root component
@@ -151,6 +152,52 @@ export const PostShow = () => (
151152
);
152153
```
153154

155+
## `aside`
156+
157+
You can pass an aside element to the `<Show>` component. It will be rendered on the right side of the page, below the actions toolbar.
158+
159+
The aside component renders in the same `RecordContext` as the `Show` child component. That means you can display details of the current `record` in the aside component by calling `useRecordContext`:
160+
161+
{% raw %}
162+
```jsx
163+
import {
164+
Show,
165+
SimpleShowLayout,
166+
TextField,
167+
DateField,
168+
RichTextField,
169+
useRecordContext
170+
} from 'react-admin';
171+
172+
export const PostShow = () => (
173+
<Show aside={<Aside />}>
174+
<SimpleShowLayout>
175+
<TextField source="title" />
176+
<TextField source="teaser" />
177+
<RichTextField source="body" />
178+
<DateField label="Publication date" source="published_at" />
179+
</SimpleShowLayout>
180+
</Show>
181+
);
182+
183+
const Aside = () => {
184+
const record = useRecordContext();
185+
return (
186+
<div style={{ width: 200, margin: '1em' }}>
187+
<Typography variant="h6">Post details</Typography>
188+
{record && (
189+
<Typography variant="body2">
190+
Creation date: {record.createdAt}
191+
</Typography>
192+
)}
193+
</div>
194+
);
195+
};
196+
```
197+
{% endraw %}
198+
199+
**Tip**: Always test the record is defined before using it, as react-admin starts rendering the UI before the `dataProvider.getOne()` call is over.
200+
154201
## `queryOptions`
155202

156203
`<Show>` accepts a `queryOptions` prop to pass options to the react-query client.

0 commit comments

Comments
 (0)