import React , { FC , createContext , useState } from 'react' ; export type NamespaceType = { [ key ] : any ; } ; export interface GlobalContextProps { globalNamespace : NamespaceType ; contentfulId : string ; setGlobalNamespace : ( ns : NamespaceType ) => void ; setContentfulId : ( id : string ) => void ; } export interface GlobalContextProviderProps { namespace ? : NamespaceType ; } export const GlobalContext = createContext < GlobalContextProps > ( { globalNamespace : { } , contentfulId : '' , setGlobalNamespace : ( ) => null , setContentfulId : ( ) => null , } ) ; export const GlobalContextProvider = ( { namespace = { } , children , } ) => { const setContentfulId = ( id ) => { setState ( { ... state , contentfulId : id } ) ; } ; const setGlobalNamespace = ( ns ) => { setState ( { ... state , globalNamespace : ns } ) ; } ; const initialState = { globalNamespace : namespace , contentfulId : '' , setGlobalNamespace , setContentfulId , } ; const [ state , setState ] = useState ( initialState ) ; return ( < GlobalContext . Provider value = { state } > { children } < /GlobalContext.Provider>); } ; export default GlobalContext ;