Skip to content

Commit c31dde5

Browse files
committed
Update <ShowBase> documentation
1 parent 80a1878 commit c31dde5

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

docs/ShowBase.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ const App = () => (
6363
| Prop | Required | Type | Default | Description
6464
|------------------|----------|-------------------|---------|--------------------------------------------------------
6565
| `children` | Optional | `ReactNode` | | The components rendering the record fields
66-
| `render` | Optional | `(props: ShowControllerResult<RecordType>) => ReactNode` | | Alternative to children, a function that takes the ShowController context and renders the form
66+
| `render` | Optional | `(props: ShowControllerResult<RecordType>) => ReactNode` | | Alternative to children, a function that takes the ShowController context and renders the form
6767
| `disable Authentication` | Optional | `boolean` | | Set to `true` to disable the authentication check
68-
| `empty WhileLoading` | Optional | `boolean` | | Set to `true` to return `null` while the list is loading
6968
| `id` | Optional | `string` | | The record identifier. If not provided, it will be deduced from the URL
69+
| `loading` | Optional | `ReactNode` | | The component to render while checking for authentication and permissions
70+
| `offline` | Optional | `ReactNode` | | The component to render when there is no connectivity and the record isn't in the cache
7071
| `queryOptions` | Optional | `object` | | The options to pass to the `useQuery` hook
7172
| `resource` | Optional | `string` | | The resource name, e.g. `posts`
7273

@@ -139,6 +140,8 @@ const BookShow = () => (
139140
By default, the `<ShowBase>` 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`.
140141

141142
```jsx
143+
import { ShowBase } from 'ra-core';
144+
142145
const PostShow = () => (
143146
<ShowBase disableAuthentication>
144147
...
@@ -151,6 +154,8 @@ const PostShow = () => (
151154
By default, `<ShowBase>` 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.
152155

153156
```jsx
157+
import { ShowBase } from 'ra-core';
158+
154159
export const PostShow = () => (
155160
<ShowBase id="123">
156161
...
@@ -160,6 +165,48 @@ export const PostShow = () => (
160165

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

168+
## `loading`
169+
170+
By default, `<ShowBase>` renders nothing while checking for authentication and permissions. You can provide your own component via the `loading` prop:
171+
172+
```jsx
173+
import { ShowBase } from 'ra-core';
174+
175+
export const PostShow = () => (
176+
<ShowBase loading={<p>Checking for permissions...</p>}>
177+
...
178+
</ShowBase>
179+
);
180+
```
181+
182+
## `offline`
183+
184+
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:
185+
186+
```jsx
187+
import { ShowBase } from 'ra-core';
188+
189+
export const PostShow = () => (
190+
<ShowBase offline={<p>No network. Could not load the post.</p>}>
191+
...
192+
</ShowBase>
193+
);
194+
```
195+
196+
**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:
197+
198+
```jsx
199+
import { ShowBase, IsOffline } from 'ra-core';
200+
201+
export const PostShow = () => (
202+
<ShowBase offline={<p>No network. Could not load the post.</p>}>
203+
<IsOffline>
204+
No network. The post data may be outdated.
205+
</IsOffline>
206+
</ShowBase>
207+
);
208+
```
209+
163210
## `queryOptions`
164211

165212
`<ShowBase>` accepts a `queryOptions` prop to pass options to the react-query client.
@@ -210,6 +257,8 @@ The default `onError` function is:
210257
By default, `<ShowBase>` 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.
211258

212259
```jsx
260+
import { ShowBase } from 'ra-core';
261+
213262
export const UsersShow = () => (
214263
<ShowBase resource="users">
215264
...

0 commit comments

Comments
 (0)