Skip to content

Commit c5f9f5a

Browse files
committed
[Doc] Add Show documentation
1 parent ff20e36 commit c5f9f5a

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

docs/Show.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ That's enough to display the post show view above.
6161

6262
| Prop | Required | Type | Default | Description
6363
|------------------|----------|-------------------|---------|--------------------------------------------------------
64-
| `children` | Required if no render | `ReactNode` | | The components rendering the record fields
65-
| `render` | Required if no children | `(showContext) => ReactNode` | | A function rendering the record fields, receive the show context as its argument
64+
| `children` | Optional * | `ReactNode` | | The components rendering the record fields
65+
| `render` | Optional * | `(showContext) => ReactNode` | | A function rendering the record fields, receive the show context as its argument
6666
| `actions` | Optional | `ReactElement` | | The actions to display in the toolbar
6767
| `aside` | Optional | `ReactElement` | | The component to display on the side of the list
6868
| `className` | Optional | `string` | | passed to the root component
@@ -75,6 +75,8 @@ That's enough to display the post show view above.
7575
| `sx` | Optional | `object` | | Override or extend the styles applied to the component
7676
| `title` | Optional | `string | ReactElement | false` | | The title to display in the App Bar
7777

78+
`*` You must provide either `children` or `render`.
79+
7880
## `actions`
7981

8082
By default, `<Show>` includes an action toolbar with an `<EditButton>` if the `<Resource>` declared an `edit` component. You can replace the list of default actions by your own component using the `actions` prop:
@@ -174,6 +176,8 @@ export const PostShow = () => (
174176

175177
You can also pass a React element as child, to build a custom layout. Check [Building a custom Show Layout](./ShowTutorial.md#building-a-custom-layout) for more details.
176178

179+
You can also use [the `render` prop](#render) to define a custom render function for the show view.
180+
177181
**Tip**: Use [`<ShowGuesser>`](./ShowGuesser.md) instead of `<Show>` to let react-admin guess the fields to display based on the dataProvider response.
178182

179183
## `component`
@@ -341,6 +345,28 @@ The default `onError` function is:
341345
}
342346
```
343347

348+
## `render`
349+
350+
Instead of passing a `children` prop, you can pass a `render` prop, which is a function that receives the [`ShowContext`](./useShowContext.md#return-value) as an argument and returns the React element to render. This allows you to access the `record`, `isPending`, and other properties from the `showContext`.
351+
352+
```tsx
353+
import { Show } from 'react-admin';
354+
355+
export const PostShow = () => (
356+
<Show render={({ record, error, isPending }) => {
357+
if (isPending) return <p>Loading...</p>;
358+
if (error) return <p>Error: {error.message}</p>;
359+
if (!record) return <p>No record found</p>;
360+
return (
361+
<div>
362+
<h1>{record.title}</h1>
363+
<p>{record.body}</p>
364+
</div>
365+
);
366+
}} />
367+
);
368+
```
369+
344370
## `resource`
345371

346372
By default, `<Show>` operates on the current `ResourceContext` (defined at the routing level), so under the `/posts/1/show` path, the `resource` prop will be `posts`. You may want to force a different resource. In this case, pass a custom `resource` prop, and it will override the `ResourceContext` value.

0 commit comments

Comments
 (0)