-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.js
39 lines (30 loc) · 802 Bytes
/
index.js
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
import React from 'react';
import client from '../api/client';
import { useQuery } from 'react-fetching-library';
const action = {
method: 'GET',
endpoint: 'https://private-34f3a-reactapiclient.apiary-mock.com/users',
};
const Users = () => {
const { loading, payload, error, query } = useQuery(action, true);
return (
<div>
{loading && <span>Loading</span>}
{error && <span>Error</span>}
{!loading &&
payload &&
payload.map((user, index) => (
<span key={user.uuid}>
{index + 1} - {user.firstName} <br />
<br />
</span>
))}
<button onClick={query}>Reload</button>
</div>
);
};
Users.getInitialProps = async () => {
await client.query(action);
return {};
};
export default Users;