-
-
Notifications
You must be signed in to change notification settings - Fork 242
/
Home.tsx
executable file
·48 lines (38 loc) · 1.26 KB
/
Home.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
37
38
39
40
41
42
43
44
45
46
47
48
import { FC, useEffect, memo } from "react";
import { RouteComponentProps } from "react-router-dom";
import { useDispatch, useSelector, shallowEqual } from "react-redux";
import { Helmet } from "react-helmet";
import { AppState, AppThunk } from "../../store";
import { fetchUserListIfNeed } from "../../store/userList";
import { List } from "../../components";
import styles from "./styles.module.scss";
export type Props = RouteComponentProps;
const Home: FC<Props> = (): JSX.Element => {
const dispatch = useDispatch();
const { readyStatus, items } = useSelector(
({ userList }: AppState) => userList,
shallowEqual
);
// Fetch client-side data here
useEffect(() => {
dispatch(fetchUserListIfNeed());
}, [dispatch]);
const renderList = () => {
if (!readyStatus || readyStatus === "invalid" || readyStatus === "request")
return <p>Loading...</p>;
if (readyStatus === "failure") return <p>Oops, Failed to load list!</p>;
return <List items={items} />;
};
return (
<div className={styles.Home}>
<Helmet title="Home" />
{renderList()}
</div>
);
};
// Fetch server-side data here
export const loadData = (): AppThunk[] => [
fetchUserListIfNeed(),
// More pre-fetched actions...
];
export default memo(Home);