Skip to content

Data is being re-fetched on window re-focus always, without consuming from cached data. #838

@mustafa-alfar

Description

@mustafa-alfar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions