useGetOneLive
This Enterprise Edition hook, alternative to
useGetOne
, subscribes to live updates on the record.
Usage
import { useRecordContext } from 'react-admin';
import { useGetOneLive } from '@react-admin/ra-realtime';
const UserProfile = () => {
const record = useRecordContext();
const { data, isLoading, error } = useGetOneLive('users', { id: record.userId });
if (isLoading) {
return <Loading />;
}
if (error) {
return <p>ERROR</p>;
}
return <div>User {data.username}</div>;
};
The hook will subscribe to live updates on the record (topic: resource/[resource]/[id]
) and will refetch the record when it is updated or deleted.
See the useGetOne
documentation for the full list of parameters and return type.