import React , { useEffect } from 'react' ; import { travisCIApiRef } from '../api' ; import { useLocalStorage } from 'react-use' ; import { Entity } from '@backstage/catalog-model' ; export type Settings = { entity : Entity ; } ; export const StateContext = React . createContext < [ Settings , React . Dispatch < Settings > ] > ( [ ] as any ) ; const STORAGE_KEY = `${ travisCIApiRef . id }.settings` ; type Props = { entity : Entity ; } ; export const ContextProvider = ( { entity , children } ) => { const [ settings , setSettings ] = useLocalStorage ( STORAGE_KEY , { entity } ) ; if ( settings === undefined ) { throw new Error ( 'Firebase functions plugin settings is undefined' ) ; } useEffect ( ( ) => { if ( settings . entity !== entity ) { setSettings ( { entity } ) ; } } , [ entity ] ) ; return ( < StateContext . Provider value = { [ settings , setSettings ] } > < > { children } < /> < /StateContext.Provider>); } ;