Skip to content

Commit 7ccd7ef

Browse files
committed
Update <Show> documentation
1 parent c31dde5 commit 7ccd7ef

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

docs/Show.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ That's enough to display the post show view above.
7070
| `disable Authentication` | Optional | `boolean` | | Set to `true` to disable the authentication check
7171
| `empty WhileLoading` | Optional | `boolean` | | Set to `true` to return `null` while the show is loading
7272
| `id` | Optional | `string | number` | | The record id. If not provided, it will be deduced from the URL
73+
| `offline` | Optional | `ReactNode` | | The component to render when there is no connectivity and the record isn't in the cache
7374
| `queryOptions` | Optional | `object` | | The options to pass to the `useQuery` hook
7475
| `resource` | Optional | `string` | | The resource name, e.g. `posts`
7576
| `sx` | Optional | `object` | | Override or extend the styles applied to the component
@@ -83,7 +84,7 @@ By default, `<Show>` includes an action toolbar with an `<EditButton>` if the `<
8384

8485
```jsx
8586
import Button from '@mui/material/Button';
86-
import { EditButton, TopToolbar } from 'react-admin';
87+
import { EditButton, Show, TopToolbar } from 'react-admin';
8788

8889
const PostShowActions = () => (
8990
<TopToolbar>
@@ -158,6 +159,8 @@ React-admin provides 2 built-in show layout components:
158159
To use an alternative layout, switch the `<Show>` child component:
159160

160161
```diff
162+
import { Show } from 'react-admin';
163+
161164
export const PostShow = () => (
162165
<Show>
163166
- <SimpleShowLayout>
@@ -188,6 +191,7 @@ You can override the main area container by passing a `component` prop:
188191

189192
{% raw %}
190193
```jsx
194+
import { Show } from 'react-admin';
191195
import { Box } from '@mui/material';
192196

193197
const ShowWrapper = ({ children }) => (
@@ -210,6 +214,8 @@ const PostShow = () => (
210214
By default, the `<Show>` component will automatically redirect the user to the login page if the user is not authenticated. If you want to disable this behavior and allow anonymous access to a show page, set the `disableAuthentication` prop to `true`.
211215

212216
```jsx
217+
import { Show } from 'react-admin';
218+
213219
const PostShow = () => (
214220
<Show disableAuthentication>
215221
...
@@ -273,6 +279,8 @@ const BookShow = () => (
273279
By default, `<Show>` deduces the identifier of the record to show from the URL path. So under the `/posts/123/show` path, the `id` prop will be `123`. You may want to force a different identifier. In this case, pass a custom `id` prop.
274280

275281
```jsx
282+
import { Show } from 'react-admin';
283+
276284
export const PostShow = () => (
277285
<Show id="123">
278286
...
@@ -282,6 +290,35 @@ export const PostShow = () => (
282290

283291
**Tip**: Pass both a custom `id` and a custom `resource` prop to use `<Show>` independently of the current URL. This even allows you to use more than one `<Show>` component in the same page.
284292

293+
## `offline`
294+
295+
By default, `<ShowBase>` renders nothing when there is no connectivity and the record hasn't been cached yet. You can provide your own component via the `offline` prop:
296+
297+
```jsx
298+
import { Show } from 'react-admin';
299+
300+
export const PostShow = () => (
301+
<Show offline={<p>No network. Could not load the post.</p>}>
302+
...
303+
</Show>
304+
);
305+
```
306+
307+
**Tip**: If the record is in the Tanstack Query cache but you want to warn the user that they may see an outdated version, you can use the `<IsOffline>` component:
308+
309+
```jsx
310+
import { Show, IsOffline } from 'react-admin';
311+
312+
export const PostShow = () => (
313+
<Show offline={<p>No network. Could not load the post.</p>}>
314+
<IsOffline>
315+
No network. The post data may be outdated.
316+
</IsOffline>
317+
...
318+
</Show>
319+
);
320+
```
321+
285322
## `queryOptions`
286323

287324
`<Show>` accepts a `queryOptions` prop to pass options to the react-query client.
@@ -372,6 +409,8 @@ export const PostShow = () => (
372409
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.
373410

374411
```jsx
412+
import { Show } from 'react-admin';
413+
375414
export const UsersShow = () => (
376415
<Show resource="users">
377416
...

docs/ShowBase.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export const PostShow = () => (
203203
<IsOffline>
204204
No network. The post data may be outdated.
205205
</IsOffline>
206+
...
206207
</ShowBase>
207208
);
208209
```

0 commit comments

Comments
 (0)