I am trying to pass a function as a parameter to custom hooks I created. The file that uses the hooks and it is it self a custom hook is this:
export const MainStore = () => {
...
const checkForRefreshTokenUpdate = async () => {
...
}
const { getAssetData } = assets(checkForRefreshTokenUpdate());
...
}
second file:
export const assets = ( checkForRefreshTokenUpdate ) => {
const { customAxios } = interceptedAxios(checkForRefreshTokenUpdate);
/**
* Fetches asset data.
* @returns
*/
const getAssetData = async (params) => {
const url = buildUrl({
baseUrl: getBaseUrl(),
endpoint: "/api/asset",
params
});
const reqOpts = {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${getAccessToken()}`
}
};
return customAxios.get(url, reqOpts).then(res => { res.data });
};
return { getAssetData }
}
third file:
export const interceptedAxios = ( checkForRefreshTokenUpdate ) => {
const customAxios = axios.create();
customAxios.interceptors.request.use(async (config) => {
if (config.url.includes(getBaseUrl()) && config.headers["Authorization"] != null) {
await checkForRefreshTokenUpdate()
.then((token) => {
if (token != null) {
config.headers["Authorization"] = `Bearer ${token}`;
}
});
}
return config;
},
(error) => {
return Promise.reject(error);
});
return { customAxios }
}
I keep getting error: ReferenceError: checkForRefreshTokenUpdate is not defined.
Is there anything wrong in syntax?