Skip to content

Commit

Permalink
Merge pull request #6376 from marmelab/fix-show-aside-component
Browse files Browse the repository at this point in the history
[Doc] Fix `<Show aside>` prop format is component instead of element
  • Loading branch information
djhi authored Jun 21, 2021
2 parents 49810c3 + 7654b07 commit 15ef772
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions docs/Show.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const PostShow = (props) => (

![Aside component](./img/aside.png)

You may want to display additional information on the side of the resource detail. Use the `aside` prop for that, passing the component of your choice:
You may want to display additional information on the side of the resource detail. Use the `aside` prop for that, passing the element of your choice:

{% raw %}
```jsx
Expand All @@ -141,27 +141,30 @@ const Aside = () => (
);

const PostShow = props => (
<Show aside={Aside} {...props}>
<Show aside={<Aside />} {...props}>
...
</Show>
);
```
{% endraw %}

The `aside` component receives the same props as the `Show` child component: `basePath`, `record`, `resource`, and `version`. That means you can display secondary details of the current record in the aside component:
You can use the `useRecordContext` hook to display non-editable details about the current record in the aside component:

{% raw %}
```jsx
const Aside = ({ record }) => (
<div style={{ width: 200, margin: '1em' }}>
<Typography variant="h6">Post details</Typography>
{record && (
<Typography variant="body2">
Creation date: {record.createdAt}
</Typography>
)}
</div>
);
const Aside = () => {
const record = useRecordContext();
return (
<div style={{ width: 200, margin: '1em' }}>
<Typography variant="h6">Post details</Typography>
{record && (
<Typography variant="body2">
Creation date: {record.createdAt}
</Typography>
)}
</div>
);
}
```
{% endraw %}

Expand Down

0 comments on commit 15ef772

Please sign in to comment.