Skip to content

useGetOneLive

An alternative to useGetOne() that subscribes to live updates on the record

This feature requires a valid Enterprise Edition subscription.

Terminal window
npm install --save @react-admin/ra-core-ee
# or
yarn add @react-admin/ra-core-ee
import { useRecordContext } from 'ra-core';
import { useGetOneLive } from '@react-admin/ra-core-ee';
const UserProfile = () => {
const record = useRecordContext();
const { data, isLoading, error } = useGetOneLive('users', {
id: record.id,
});
if (isLoading) {
return <div>Loading...</div>;
}
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.