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/client/hooks/useUserData.ts

28 lines
694 B

import { useMemo } from 'react';
import { useSubscription } from 'use-subscription';
import { Presence, UserPresence } 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 = useMemo(
() => ({
getCurrentValue: (): UserPresence | undefined => Presence.store.get(uid),
subscribe: (callback: any): any => {
Presence.listen(uid, callback);
return (): void => {
Presence.stop(uid, callback);
};
},
}),
[uid],
);
return useSubscription(subscription);
};