-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
77 lines (66 loc) · 1.48 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
73
74
75
76
77
import logo from './logo.svg';
import './App.css';
import React ,{useState}from 'react'
import { useLazyQuery, gql } from "@apollo/client";
function App() {
const [print,setPrint]=useState(false)
// const [data,setData]=useState(null)
const [query,setQuery]=useState(null)
function getData(val)
{
console.warn(val.target.value)
setPrint(false)
}
const FILMS_QUERY = gql`
{
launchesPast(limit: 10) {
id
mission_name
}
}
`;
const [
getQuery,
{ loading, data }
] = useLazyQuery(FILMS_QUERY);
if (loading) return <p>Loading ...</p>;
if (data && data.launchesPast) {
console.log(data.launchesPast);
}
return (
<div className="App">
<input type="text" />
<button onClick={()=>getQuery()} > Search </button>
<div>
<h1>SpaceX Launches</h1>
<ul>
{data?.launchesPast.map((launch) => (
<li key={launch.id}>{launch.mission_name}</li>
))}
</ul>
</div>
</div>
);
}
export default App;
/*
export function DelayedCountries() {
const [
getCountries,
{ loading, data }
] = useLazyQuery(GET_COUNTRIES);
if (loading) return <p>Loading ...</p>;
if (data && data.countries) {
console.log(data.countries);
}
return (
<div>
<button onClick={() => getCountries()}>
Click me to print all countries!
</button>
{data &&
data.countries &&
data.countries.map((c, i) => <div key={i}>{c.name}</div>)
</div>
);
}*/