You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `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
66
66
| `actions` | Optional | `ReactElement` | | The actions to display in the toolbar
67
67
| `aside` | Optional | `ReactElement` | | The component to display on the side of the list
68
68
| `className` | Optional | `string` | | passed to the root component
@@ -75,6 +75,8 @@ That's enough to display the post show view above.
75
75
| `sx` | Optional | `object` | | Override or extend the styles applied to the component
76
76
| `title` | Optional | `string | ReactElement | false` | | The title to display in the App Bar
77
77
78
+
`*` You must provide either `children` or `render`.
79
+
78
80
## `actions`
79
81
80
82
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:
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.
176
178
179
+
You can also use [the `render` prop](#render) to define a custom render function for the show view.
180
+
177
181
**Tip**: Use [`<ShowGuesser>`](./ShowGuesser.md) instead of `<Show>` to let react-admin guess the fields to display based on the dataProvider response.
178
182
179
183
## `component`
@@ -341,6 +345,28 @@ The default `onError` function is:
341
345
}
342
346
```
343
347
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
+
exportconst PostShow = () => (
356
+
<Showrender={({ 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
+
344
370
## `resource`
345
371
346
372
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