Real-Time Updates And Locks
Teams where several people work in parallel on a common task need to allow live updates, real-time notifications, and prevent data loss when two editors work on the same resource concurrently.
React-admin offers powerful realtime features to help you build collaborative applications, based on the Publish / Subscribe (PubSub) pattern. The Realtime documentation explains how to use them.
These features are part of the Enterprise Edition.
Realtime Data Provider
The realtime features are backend agnostic. Just like for CRUD operations,realtime operations rely on the data provider, using additional methods:
dataProvider.subscribe(topic, callback)
dataProvider.unsubscribe(topic, callback)
dataProvider.publish(topic, event)
(optional - publication is often done server-side)
In addition, to support the lock features, the dataProvider
must implement 4 more methods:
dataProvider.lock(resource, { id, identity, meta })
dataProvider.unlock(resource, { id, identity, meta })
dataProvider.getLock(resource, { id, meta })
dataProvider.getLocks(resource, { meta })
You can implement these features using any realtime backend, including:
- Mercure,
- API Platform,
- supabase,
- Socket.IO,
- Ably,
- and many more.
Check the Realtime Data Provider documentation for more information, and for helpers to build your own realtime data provider.
Realtime Hooks And Components
Once your data provider has enabled realtime features, you can use these hooks and components to build realtime applications:
usePublish
useSubscribe
useSubscribeCallback
useSubscribeToRecord
useSubscribeToRecordList
useLock
useUnlock
useGetLock
useGetLockLive
useGetLocks
useGetLocksLive
useLockOnMount
useLockOnCall
useGetListLive
useGetOneLive
<ListLive>
<EditLive>
<ShowLive>
<MenuLive>
Refer to the Realtime documentation for more information.