You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/shared/redux/hooks/useUserInfo.ts

30 lines
753 B
TypeScript

import { getCachedUserInfo } from '../../cache/cache';
import { useAsync } from '../../hooks/useAsync';
import type { UserLoginInfo } from '../../model/user';
import { useAppSelector } from './useAppSelector';
/**
*
*/
export function useUserInfo(): UserLoginInfo | null {
return useAppSelector((state) => state.user.info);
}
/**
* Id
*/
export function useUserId(): string | undefined {
return useUserInfo()?._id;
}
/**
* id
*/
export function useUserInfoList(userIds: string[]) {
const { value: userInfos = [] } = useAsync(() => {
return Promise.all(userIds.map((userId) => getCachedUserInfo(userId)));
}, [userIds.join(',')]);
return userInfos;
}