digitalfabrik/integreat-app

View on GitHub
native/src/hooks/useResourceCache.ts

Summary

Maintainability
A
0 mins
Test Coverage
B
83%
import { useCallback } from 'react'

import { useLoadAsync } from 'shared/api'

import { LanguageResourceCacheStateType } from '../utils/DataContainer'
import dataContainer from '../utils/DefaultDataContainer'

type UseResourceCacheProps = {
  cityCode: string
  languageCode: string
}

const useResourceCache = ({ cityCode, languageCode }: UseResourceCacheProps): LanguageResourceCacheStateType =>
  useLoadAsync(useCallback(() => dataContainer.getResourceCache(cityCode, languageCode), [cityCode, languageCode]))
    .data ?? {}

export default useResourceCache