I have a simple example where I have a circular dependency issue. What can be done to avoid this importing loop?
store.js
import { fetchApi } from "./api";
class Store {
auth = "zzzzz";
fetch = () => fetchApi();
}
const store = new Store();
export default store;
api.js
import client from "./client";
export const fetchApi = () => client("/test");
client.js
import store from "./store";
const client = (endpoint) => {
const config = {
method: "GET",
headers: {
Authorization: `Bearer ${store.auth}`
}
};
return window.fetch(endpoint, config);
};
export default client;
With this code, I have the following situation:
store -> api -> client -> store
Happy to hear suggestions or see examples on how can I avoid this pattern. ๐๐ป