Last active
June 9, 2021 11:39
-
-
Save sayon-bitquery/ab0f4494640330aa2d832b44861bea4c to your computer and use it in GitHub Desktop.
In the App() of the src/App.js we’ll then make a React component that will have the data from the useQuery function which in turn uses the fetch API and also, we need to specify a header that includes the content type of the data that we want back from our request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function App() { | |
const { data, isLoading, error } = useQuery("bitcoin", () => { //launches | |
return fetch(endpoint, { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
"X-API-KEY": "YOUR API KEY" | |
}, | |
body: JSON.stringify({ query: QUERY }) // ({ QUERY }) | |
}) | |
.then((response) => { | |
if (response.status >= 400) { | |
throw new Error("Error fetching data"); | |
} else { | |
return response.json(); | |
} | |
}) | |
.then((data) => data.data); | |
}); | |
if (isLoading) return "Loading..."; | |
if (error) return <pre>{error.message}</pre>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment