-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathcustomRouteNoLayout.tsx
42 lines (36 loc) · 1.06 KB
/
customRouteNoLayout.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
import * as React from 'react';
import { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { crudGetList } from 'react-admin';
const CustomRouteNoLayout = () => {
const dispatch = useDispatch();
const loaded = useSelector(
state =>
state.admin.resources.posts &&
state.admin.resources.posts.list.total > 0
);
const total = useSelector(state =>
state.admin.resources.posts ? state.admin.resources.posts.list.total : 0
);
useEffect(() => {
dispatch(
crudGetList(
'posts',
{ page: 0, perPage: 10 },
{ field: 'id', order: 'ASC' }
)
);
}, [dispatch]);
return (
<div>
<h1>Posts</h1>
{!loaded && <p className="app-loader">Loading...</p>}
{loaded && (
<p>
Found <span className="total">{total}</span> posts !
</p>
)}
</div>
);
};
export default CustomRouteNoLayout;