import React , { FC , createContext , useState , useEffect , ReactElement } from 'react' ; import { useQuery } from '@apollo/client' ; import GET_APP_BY_ID_QUERY from '@graphql/apps/getAppById.query' ; interface iAppContext { state : any ; } interface iProps { id : any ; children : ReactElement ; } export const AppContext = createContext < iAppContext > ( { state : { } } ) ; const AppProvider = ( { id , children } ) : ReactElement => { const [ state , setState ] = useState ( { } ) ; const { data : dataApp } = useQuery ( GET_APP_BY_ID_QUERY , { variables : { id } } ) ; useEffect ( ( ) => { if ( dataApp ) { setState ( { getAppById : dataApp . getAppById } ) ; } } , [ dataApp ] ) ; const context = { state } ; return < AppContext . Provider value = { context } > { children } < /AppContext.Provider>; } ; export default AppProvider ;