The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/hooks/useUserData.ts

27 lines
721 B

import { useCallback } from 'react';
import { useSyncExternalStore } from 'use-sync-external-store/shim';
import { UserPresence, Presence } from '../lib/presence';
/**
* Hook to fetch and subscribe users data
*
* @param uid - User Id
* @returns Users data: status, statusText, username, name
* @public
*/
export const useUserData = (uid: string): UserPresence | undefined => {
const subscription = useCallback(
(callback: () => void): (() => void) => {
Presence.listen(uid, callback);
return (): void => {
Presence.stop(uid, callback);
};
},
[uid],
);
const getSnapshot = (): UserPresence | undefined => Presence.store.get(uid);
return useSyncExternalStore(subscription, getSnapshot);
};