import React, { FC, ReactElement, ComponentType, useEffect, useState } from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { useIsMounted } from 'app/hooks'; import authFlow from 'app/services/authFlow'; interface Props extends RouteComponentProps { component: ComponentType; } const AuthFlowRouteContents: FC = ({ component: WantedComponent, location, match, history }) => { const isMounted = useIsMounted(); const [component, setComponent] = useState(null); useEffect(() => { authFlow.handleRequest( { path: location.pathname, params: match.params, query: new URLSearchParams(location.search), }, history.push, () => { if (isMounted()) { setComponent(); } }, ); }, [location.pathname, location.search]); return component; }; export default AuthFlowRouteContents;