-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Description
Describe the bug
I have tested the useQuery on Github's username API and it works well. However, when I try it on an API that's deployed on Heroku, the data re-fetches on every refresh, I also made a small change between the two experiments, I add a shop key to the headers
To Reproduce
Steps to reproduce the behaviour:
here's the code.
import React from "react";
import axios from 'axios';
import { useQuery } from "react-query";
const config = {
dev: {
baseURL: 'https://bonat-ecommerce.herokuapp.com/api/v1',
headers: {
shop: 'https://bonat-dev.myshopify.com',
Accept: 'application/json',
'Content-Type': 'application/json',
},
},
};
export const dev = axios.create({ ...config.dev });
const getThemeAPI = async () => {
const {data } = await dev.get(`/customer/init`);
return data;
}
export default function App() {
const { isLoading, error, data } = useQuery("theme", getThemeAPI);
if (isLoading) return <h1>Loading </h1>;
if (error) return <h1>Error </h1>;
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
);
}
Expected behaviour
Data should be consumed from the cached data as it also appears in the react-query dev-tools.
adriangzz, mustafa-alfar, wscourge and collinscoder1
Metadata
Metadata
Assignees
Labels
No labels