Skip to content

Commit 29e01f2

Browse files
authored
Merge pull request #11008 from marmelab/doc/realtime-components
[Doc] Add documentation for <LockOnMount> and <WithLocks> headless components
2 parents bdcee65 + ea7ecfa commit 29e01f2

File tree

4 files changed

+740
-0
lines changed

4 files changed

+740
-0
lines changed

docs_headless/astro.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,11 @@ export default defineConfig({
232232
{
233233
label: 'Realtime',
234234
items: [
235+
enterpriseEntry('RealtimeFeatures', 'Setting Up'),
235236
enterpriseEntry('<ListLiveUpdate>'),
237+
enterpriseEntry('<LockOnMount>'),
236238
enterpriseEntry('<LockStatusBase>'),
239+
enterpriseEntry('<WithLocks>'),
237240
enterpriseEntry('usePublish'),
238241
enterpriseEntry('useSubscribe'),
239242
enterpriseEntry('useSubscribeCallback'),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: '<LockOnMount>'
3+
---
4+
5+
`<LockOnMount />` calls [`dataProvider.lock()`](./RealtimeFeatures.md#data-provider-requirements) on mount and [`dataProvider.unlock()`](./RealtimeFeatures.md#data-provider-requirements) on unmount to lock and unlock the record. It relies on [`authProvider.getIdentity()`](./AuthProviderWriting.md#getidentity) to get the identity of the current user. It guesses the current `resource` and `recordId` from the context (or the route) if not provided.
6+
7+
This feature requires a valid [Enterprise Edition](https://marmelab.com/ra-enterprise/) subscription.
8+
9+
## Installation
10+
11+
```bash
12+
npm install --save @react-admin/ra-core-ee
13+
# or
14+
yarn add @react-admin/ra-core-ee
15+
```
16+
17+
## Usage
18+
19+
```tsx
20+
import { EditBase, Form } from 'ra-core';
21+
import { LockOnMount, useLockCallbacks } from '@react-admin/ra-core-ee';
22+
23+
const PostEdit = () => (
24+
<EditBase>
25+
<PostEditForm />
26+
<LockOnMount />
27+
</EditBase>
28+
);
29+
30+
const PostEditForm = () => {
31+
const { isPending, isLocked } = useLockCallbacks();
32+
33+
if (isPending) {
34+
return <p>Loading...</p>;
35+
}
36+
37+
return <Form disabled={isLocked}>{/* ... */}</Form>;
38+
};
39+
```

0 commit comments

Comments
 (0)