hooks#useTracking JavaScript Examples
The following examples show how to use
hooks#useTracking.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From dstack-server with Apache License 2.0 | 4 votes |
App = ({location, fetchUser, userData, userLoading, history: {push}, setSearch}: Props) => {
const [loading, setLoading] = useState(true);
const isInitialMount = useRef(true);
useTracking();
useEffect(() => {
if (isSignedIn())
fetchUser(
() => {},
() => {
setLoading(false);
push(routes.authLogin());
}
);
else
setLoading(false);
}, []);
useEffect(() => {
if (isInitialMount.current) {
isInitialMount.current = false;
} else {
setLoading(userLoading);
}
}, [userLoading]);
useEffect(() => {
setSearch('');
}, [location.pathname]);
return (
<div className={css.app}>
{!loading && (
<Switch>
{isSignedIn() && userData && (
<Redirect
exact
from="/"
to={routes.stacks(userData.user)}
/>
)}
<Redirect
exact
from="/"
to={routes.authLogin()}
/>
<Route path={routes.authLogin()} component={Login}/>
<DefaultLayoutRoute path={routes.verifyUser()} component={ConfirmEmail}/>
{isSignedIn() && (
<Switch>
<DefaultLayoutRoute path={routes.notFound()} component={NotFound} />
<DefaultLayoutRoute path={routes.settings()} component={Settings} />
<DefaultLayoutRoute path={routes.dashboards()} component={Dashboards} />
<DefaultLayoutRoute path={routes.stacks()} component={Stacks} />
</Switch>
)}
{!isSignedIn() && (
<Switch>
<UnAuthorizedLayoutRoute path={routes.notFound()} component={NotFound} />
<UnAuthorizedLayoutRoute path={routes.dashboards()} component={Dashboards} />
<UnAuthorizedLayoutRoute path={routes.stacks()} component={Stacks} />
</Switch>
)}
<Redirect
to={routes.notFound()}
/>
</Switch>
)}
{loading && <DefaultLayout>
<Loader />
</DefaultLayout>}
</div>
);
}