import React , { createContext , useContext } from 'react' ; const RouterContext = createContext < any > ( null ) ; function internalRouterContextTypeCheck ( context , propName , componentName ) { if ( ! context . __internalRouter ) { throw new Error ( 'The router is accessed outside the context of a <RouterProvider>.' + ' No router state will be accessible and links will not go anywhere. To fix this,' + ` make sure ${ componentName } is rendered in the context of a <RouterProvider /> element` ) ; } } export class RouterProvider extends React . Component { static contextTypes = { __internalRouter : internalRouterContextTypeCheck , } ; render ( ) { const router = this . context . __internalRouter ; return ( < RouterContext . Provider value = { router } > { this . props . children } < /RouterContext.Provider>); } } function useRouter ( ) { return useContext ( RouterContext ) ; } export default useRouter ;