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

18 lines
429 B
TypeScript

import { useQuery } from 'react-query';
import { fetchUserInfo, UserBaseInfo } from '../model/user';
function buildCacheFactory<T>(
scope: string,
fetcher: (id: string) => Promise<T>
) {
return (id: string): T | Record<string, never> => {
const { data } = useQuery([scope, id], () => fetcher(id));
return data ?? {};
};
}
export const useUserInfo = buildCacheFactory<UserBaseInfo>(
'user',
fetchUserInfo
);