-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
72 lines (51 loc) · 1.25 KB
/
App.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// (3) 2020, 7/30 fetch data by using useQuery Hook
import React from 'react';
import logo from './logo.svg';
import './App.css';
// @@@ useQuery hook
// this is a hook to fetch gql query and expose result to render
import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
import {Fragment} from 'React';
// to fetch data of first 10 users
const GET_INFO = gql`
{
user(first:10){
name,
avatar,
mail,
phone_number,
detail {
fb_id,
twitter_id
}
}
}
`
function App() {
const {data, loading, error} = useQuery(GET_INFO);
if(loading) return <p> Loading... </p>
if(error) return <p> Error </p>
return (
// map((val, index, array) => ())
<Fragment>
<div>
{data && data.user && data.user.map((res_val, index) =>(
<div>
<p>{res_val.name}</p>
<p>{res_val.detail && res_val.detail.length !== 0 && (
<p>
{""}
Users Detail:
{res_val.detail.map((sub_res_val, index)=>{
return <p key={index}> {sub_res_val.fb_id} </p>;
})}
</p>
)}</p>
</div>
))}
</div>
</Fragment>
);
}
export default App;