Skip to content

Instantly share code, notes, and snippets.

@sayon-bitquery
Last active June 9, 2021 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayon-bitquery/ab0f4494640330aa2d832b44861bea4c to your computer and use it in GitHub Desktop.
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.
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