Files
twenty/packages/twenty-front/src/modules/views/hooks/useGetViewFromCache.ts
T
Lucas Bordeau b1242bb850 4087 refactor object metadata item hooks and utils (#4861)
- Extracted each exported element from useObjectMetadataItem into its
own hook.
2024-04-09 09:19:52 +02:00

27 lines
748 B
TypeScript

import { useCallback } from 'react';
import { useApolloClient } from '@apollo/client';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
import { View } from '@/views/types/View';
export const useGetViewFromCache = () => {
const client = useApolloClient();
const cache = client.cache;
const getRecordFromCache = useGetRecordFromCache({
objectNameSingular: CoreObjectNameSingular.View,
});
const getViewFromCache = useCallback(
async (viewId: string) => {
return getRecordFromCache<View>(viewId, cache);
},
[cache, getRecordFromCache],
);
return {
getViewFromCache,
};
};