digitalfabrik/integreat-app

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

Summary

Maintainability
A
0 mins
Test Coverage
B
88%
import { useContext } from 'react'

import { AppContext, AppContextType } from '../contexts/AppContextProvider'

type UseCityAppContextReturn = AppContextType & {
  cityCode: string
}

export const useAppContext = (): AppContextType => useContext(AppContext)

const useCityAppContext = (): UseCityAppContextReturn => {
  const { cityCode, ...context } = useAppContext()
  if (!cityCode) {
    throw new Error('City code not set!')
  }
  return { cityCode, ...context }
}

export default useCityAppContext