import { useQuery } from '@apollo/react-hooks' ; import { GET_GLOBAL_DATA_QUERY } from './GetGlobalData' ; import * as R from 'rambda' ; import { CovidData } from 'types/CovidData' ; const defaultData = { closedCases : 0 , totalDeaths : 0 , totalCases : 0 , totalRecovered : 0 , activeCases : 0 } ; interface GlobalData { global : CovidData ; } const formatValues = R . pipe ( R . defaultTo < GlobalData > ( { global : defaultData } ) , R . prop ( 'global' ) ) ; export const useGlobalData = ( ) => { const { data , loading } = useQuery < GlobalData > ( GET_GLOBAL_DATA_QUERY , { variables : { } } ) ; return { globalData : formatValues ( data ) , loading } ; } ;