import React , { FunctionComponent , useEffect , useState } from "react" ; import { createRootStore , RootStore } from "./root" ; const storeContext = React . createContext < RootStore | null > ( null ) ; let rootStore ; export const StoreProvider = ( { children } ) => { const [ stores ] = useState ( ( ) => { if ( rootStore ) { return rootStore ; } rootStore = createRootStore ( ) ; return rootStore ; } ) ; useEffect ( ( ) => { return ( ) => { stores . walletConnectStore . onAndroidActivityKilled ( ) ; } ; } , [ ] ) ; return ( < storeContext . Provider value = { stores } > { children } < /storeContext.Provider>); } ; export const useStore = ( ) => { const store = React . useContext ( storeContext ) ; if ( ! store ) { throw new Error ( "You have forgot to use StoreProvider" ) ; } return store ; } ;