-
Notifications
You must be signed in to change notification settings - Fork 570
/
App.tsx
36 lines (32 loc) · 890 Bytes
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react'
import { Route, Redirect } from 'react-router'
import { useAsync } from 'react-use'
import { AuthService } from './services/AuthService'
import Layout from './components/Layout'
import Home from './routes/Home'
import ProductList from './routes/ProductList'
const getUser = () => new AuthService().getUser()
export default () => {
const state: any = useAsync(getUser)
return (
<div className="App">
<Layout>
<Route path="/" exact component={Home} />
<Route
path="/products"
render={() =>
!state.loading && state.value != null && state.value.access_token != null ? (
<ProductList />
) : (
<Redirect
to={{
pathname: '/'
}}
/>
)
}
/>
</Layout>
</div>
)
}